# Search for trig in Topics

### Did you learn trigonometry rules off by heart at school and how did you manage to survive it?

I'm having a bit of a formula overflow at the moment... Actually, the idea of learning 32 of them and reciting in class sounds a bit 19-century to me. I was even more disappointed when I opened an English Maths textbook and didn't see any signs of such terrifying practice. Did anyone here learn it, and how did you manage to survive??? PS The worst part is that we have to be able to recognise them pronounced and pronounce them, and not only be able to write them...

Question by gruffalo child    |  last reply

### what do U consider a block trig to be

Tell me whatcha think

Topic by knexfreak95    |  last reply

### Virtual Slide Rule

.  It's random and it's fun. .  Virtual Pickett N909-ES SIMPLEX TRIG RULE with METRIC CONVERSION Slide Rule .  A big "Thanks!" to caitlinsdad for the Fn graphic.

Topic by NachoMahma    |  last reply

### connecting new ping to arduino. Answered

Hi, I got ping from amazon but it has 4 leads and I do not know how to connect it to the arduino. The leads say vcc, trig, echo, and gnd. Will I be able to use the examples with ping on my arduino?  http://www.amazon.com/gp/product/B004U8TOE6/ref=oh_details_o00_s00_i00

Question by jbaker22    |  last reply

### Asking a servo to sweep on an obstacle avoidance car?

I am just a few weeks into learning how these things work, and as such, have primarily been looking at coding from examples and getting them to fit with what I am doing.  Here's the setup.  We (my students and I) have built an elegoo 4 wheeled arduino platform car.  Primarily, we are using it to autonomously move around the classroom, however we've found that the ultrasonic sensor just isn't cutting it.  We've added an optical sensor, which helps, and I've figured out the coding on getting that working.  Now, we are looking at having the servo holding the ultrasonic sensor to sweep 45 degrees to the left, then 45 to the right, and repeat.  We feel that we may be able to prevent some wall crashes and chair crashes that happen when the car comes in at an angle.  Here is the code we have now. The ABS and ACS numbers are different to account for the variances in motor manufacturing (the car wouldn't drive straight if all motors were spun up at the same speed).  We do have a second arduino hooked up mainly to control the LED's the kids added, but that code and board does not affect anything for this code and board. #include Servo myservo; int Echo = A4;  int Trig = A5; int in1 = 6; int in2 = 7; int in3 = 8; int in4 = 9; int ENA = 11; int ENB = 5; int ABS = 120; int ACS = 115; int angle = 0; const int avoidPin = 10; int rightDistance = 0,leftDistance = 0,middleDistance = 0 ; void _mForward() { analogWrite(ENA,ABS); analogWrite(ENB,ACS); digitalWrite(in1,LOW); digitalWrite(in2,HIGH); digitalWrite(in3,LOW); digitalWrite(in4,HIGH); Serial.println("go forward!"); } void _mBack() { analogWrite(ENA,ABS); analogWrite(ENB,ACS); digitalWrite(in1,HIGH); digitalWrite(in2,LOW); digitalWrite(in3,HIGH); digitalWrite(in4,LOW); Serial.println("go back!"); } void _mright() { analogWrite(ENA,ABS); analogWrite(ENB,ACS); digitalWrite(in1,LOW); digitalWrite(in2,HIGH); digitalWrite(in3,HIGH); digitalWrite(in4,LOW); Serial.println("go right!"); } void _mleft() { analogWrite(ENA,ABS); analogWrite(ENB,ACS); digitalWrite(in1,HIGH); digitalWrite(in2,LOW); digitalWrite(in3,LOW); digitalWrite(in4,HIGH); Serial.println("go left!"); } void _mStop() {   digitalWrite(ENA,LOW);   digitalWrite(ENB,LOW);   Serial.println("Stop!"); } int Distance_test()   {   digitalWrite(Trig, LOW);     delayMicroseconds(2);   digitalWrite(Trig, HIGH);    delayMicroseconds(20);   digitalWrite(Trig, LOW);     float Fdistance = pulseIn(Echo, HIGH);    Fdistance= Fdistance/58;         return (int)Fdistance; }  void setup() {   myservo.attach(3);   Serial.begin(38400);       pinMode(Echo, INPUT);      pinMode(Trig, OUTPUT);   pinMode(avoidPin, INPUT);    pinMode(in1,OUTPUT);   pinMode(in2,OUTPUT);   pinMode(in3,OUTPUT);   pinMode(in4,OUTPUT);   pinMode(ENA,OUTPUT);   pinMode(ENB,OUTPUT);    _mStop(); } void loop() {   boolean avoidVal = digitalRead (avoidPin);       myservo.write(90);     delay(500);     middleDistance = Distance_test();     #ifdef send     Serial.print("middleDistance=");     Serial.println(middleDistance);     #endif     if((middleDistance<=50) || (avoidVal==LOW))     {           _mStop();       delay(500);                               myservo.write(5);                delay(1000);            rightDistance = Distance_test();       #ifdef send       Serial.print("rightDistance=");       Serial.println(rightDistance);       #endif       delay(500);        myservo.write(90);                    delay(1000);                                                        myservo.write(180);                    delay(1000);       leftDistance = Distance_test();       #ifdef send       Serial.print("leftDistance=");       Serial.println(leftDistance);       #endif       delay(500);       myservo.write(90);                    delay(1000);       if(rightDistance>leftDistance)        {         _mright();         delay(180);        }        else if(rightDistance        {         _mleft();         delay(180);        }        else if((rightDistance<=50)||(leftDistance<=50) || (avoidVal=LOW))        {         _mBack();         delay(180);        }        else        {         _mForward();        }     }      else         _mForward();                     }

Question by KevinM560    |  last reply

### Creative ways to stay sharp on you algrebra and pre calculus skills when you're not in class? Answered

Hey, guys! Any other math enthusiast out there? I just took pre-calc with Trig last spring. My intention was to take Calc 1 this fall while pre-calc was still fresh on my mind. Unfortunately, things aren't going to work out that way. Does anyone have a really creative and fun way to stay sharp on their maths? I already have a few of my own but I want to know what other ideas people have. Thanks:) PS: My current method is solving TED riddles using systems of equations.

Question by RampedUpDIY    |  last reply

### What Code Should I use To Make a Single Pulse Trigger.

Hello World,I am currently making a circuit that will produce a single pulse using Arduino. I want that my circuit and code should produce a single pulse, after that the pin o which I am taking output becomes low until I switch off the button. the pulse should again be generated when the button is pressed.I have been using a series of codes. But, whenever I upload the sketch to the Arduino it works for once. after that when I switch the button off and turn it on again it doesn't work. If the switch is kept on after some time it again starts to generate a pulse.Please if anyone can help me out would be a great thing.Thankyou.

Question by shubhamnagla909    |  last reply

### SENSOR- Ultrasonic HC-SR04 (Interfacing HC-SR04 with 8051)

Hi friends, I am doing a project based on obstacle detector. It is a outdoor project hence i choose to buy an ultrasonic sensor to work efficiently on both bright sun light as well as dark nights. Now my problem is i am not able to interface this sensor with my controller. Anyone please tell me what input i must give to trig input of that sensor and what kind of output i get form the echo pin. also tell me how can i interface this sensor with the AT89S52. i have attached the user manual which i downloaded from internet.  Please help me with your valuable comments, Thanks in advance.

Topic by knachuthan    |  last reply

### How do I calculate mortar trajectory in a videogame?

I've been playing a lot of Gmod lately, a fantastic sandbox game with unlimited possibilities. There are many addons to Gmod, one of the more common for sandbox servers being Wiremod. There's a specific tool in wiremod called Expression2, which is a language very similar to LUA. I commited to learning E2, and I've come a long way. Being as young as I am, though, complicated math has always been a huge roadblock. I'm in 8th grade, I've never taken trig. I'm currently atempting to make a mortar of sorts, but most of the research I've done has been like an entirely different language to me. As far as I know, there's no drag or air resistance in Gmod, so I'd probably just need to include launch velocity, launch angle, launch position, and end position. All I really need is some pointers on a formula and how to use it. Anyone willing to help me out?

Question by Nuurdle    |  last reply

### Make the ping distance match the pot distance?

Hi I have a Personal Fan that is working.  But, I am trying to change the ping distance to operate a rely. Trying to get the Ping distance to track a pot input so the distance the fan will come on can be changed by the pot. In the serial monitor the pot input will change from 0 to 1024. I was not able to get the ping distance to read out and how to make the Distance value track to the input pot? Thanks to anybody that could look at this ad steer me in the write direction.  #include "Ultrasonic.h" int RELAY = 9;  // RELAY Pin. Ultrasonic sensor1(11,10); // Ultrasonic(int TP, int EP); //int TRIG = 11; // Trigger Pin //int ECHO = 10; // Echo Pin int Range; // The range of the object from Ping Sensor int Dist; // The Distance value int POTPIN = A1; //#declare relayState; int  relayState; //int distPot; distControl; //#declare distPot; int distPot; //#declare distControl; int distControl; long cm; //distance min and max const int minDistance = 2;  //dist in CM dont go below 2 const int maxDistance = 200;  //dist in CM //Ultrasonic ultrasonic(TRIG,ECHO); // Create and initialize the Ultrasonic object. void setup() {   pinMode(RELAY, OUTPUT); //To the relay via the transistor   //Dist = 15; //The distance in inches. Change this for increasted or dicreasted range. Dist = map(Dist,0, 5, 1, 1023); Serial.begin(9600); } void loop(){   //Range = ultrasonic.Ranging(CM); // Range is calculated in Centimeters. Dist = analogRead(POTPIN);   // check the distance pot   distPot = analogRead(Dist);   //distControl = map(distPot,0,1024,minDistance,maxDistance);   distControl = constrain(RELAY,0,255);   if(relayState){     Dist  = distControl.Ranging(CM);     digitalWrite(RELAY,HIGH);   }      else{      digitalWrite(RELAY,LOW);   }    // RELAY = map(cm,distControl,minDistance); //variable map formula relationship     RELAY = constrain(RELAY, 0, 255); //int i = analogRead(POTPIN); // if (i == Dist)digitalWrite(RELAY,HIGH); // else digitalWrite(RELAY,LOW);   //Range = ultrasonic.Ranging(INC); // Range is calculated in Inches.     //if (Range < Dist) {     //digitalWrite(RELAY, HIGH);     //} else if (Range > Dist)      //digitalWrite(RELAY, LOW);      //delay(90);   Serial.print(Dist); Serial.println("inch"); delay(100); //Serial.print(sensor1);   Serial.print(distControl); //Serial.println("POTPIN"); delay(100); }

Question by WWC    |  last reply

### Deriving the maximum range and angle of a projectile

In a thread in the Green group, AnarchistAsian and I were discussing his coil guns. I posed the question of what range he could get, and he asked me to go through the physics derivation. Here it is, simplified to require just algebra and trig.The kinetic energy of the projectile E = ½mv2, gives v = sqrt(2E/m) as the speed at launch. Let θ be the angle at which you launch (θ=0° is horizontal, θ=90° is straight up). Then you can decompose the speed into two components: vh = v cos(θ) is the horizontal speed,vv = v sin(θ) is the vertical speed.Gravity only pulls vertically, so the projectile's vertical speed will be slowed down until it reaches its maximum altitude, then it will fall back until it hits the ground. The horizontal speed will remain constant until it hits the ground and stops. To figure out the range, you need to know the time t that the projectile flies before it hits the ground; then the range is just R = vhtEnergy conservation guarantees that it's downward speed at the end is equal to its original upward speed, just with a change of sign. That also means that the total flight time of the projectile will be half going up and half going down. Once you determine how long it takes to reach the top of its flight, you're done; just double that answer :-)In the vertical direction, the maximum heightH = vvt - ½gt2(you need calculus to derive this result). From energy conservation, the initial kinetic energy in the vertical direction, Ev = ½mvv2 must equal the potential energy at the top of the flight, Pv = mgH:mgH = ½mvv2H = ½vv2/gSubstitute this on the left hand side of the trajectory expression,½vv2/g = vvt - ½gt2vv2 = 2gvvt - g2t2vv2 - 2gvvt + g2t2 = 0(vv - gt)2 = 0vv = gtSo, t = vv/g = v sin(θ)/g is the time to reach maximum height. Double that as discussed above, and you get the range R = 2 sin(θ) cos(θ) v/g.Work out the angle that gets you maximum range by just plugging in different angle values and finding the one that is biggest.

Topic by kelseymh    |  last reply

### Arduino Run at the same time?

Hi ,  i got problem with my code which is can't run at the same time. for the Heat is great but the ultrasonic didn't trigger the buzzer which is more than 30cm away. btw here is my code , which part should i change ? Thanks #include #define trigPin 6    //trigPin #define echoPin 7    //echoPin LiquidCrystal lcd(12,11,5,4,3,2); int tempPin = A1;   // the output pin of LM35 int fan = 10;       // the pin where fan is int led = 9;        // led pin int temp; int tempMin = 35;   // the temperature to start the fan int tempMax = 70;   // the maximum temperature when fan is at 100% int fanSpeed; int fanLCD; int duration, distance; int buzzer = LOW; void setup() {   Serial.begin (9600);        //Baud rate   pinMode (trigPin, OUTPUT);  //trig pin as output   pinMode (echoPin, INPUT);   //echo pin as input   pinMode (13, OUTPUT);       //Buzzer pin as output   pinMode(fan, OUTPUT);   pinMode(led, OUTPUT);   pinMode(tempPin, INPUT);   lcd.begin(16,2);   } void ultrasonic() {   digitalWrite (trigPin, HIGH);   delayMicroseconds (1000);   digitalWrite (trigPin, LOW);   duration = pulseIn (echoPin, HIGH);   distance = (duration/2) / 29.1;   if (distance > 30)   {     Serial.print(distance);     Serial.println(" cm");     digitalWrite (13, HIGH);   }   else   {     Serial.println (distance);     Serial.println ( "cm");     digitalWrite (13, LOW);   } } void heat() {   temp = readTemp();     // get the temperature   if(temp < tempMin) {   // if temp is lower than minimum temp     fanSpeed = 0;      // fan is not spinning     digitalWrite(fan, LOW);         }   if((temp >= tempMin) && (temp <= tempMax)) {  // if temperature is higher than minimum temp     fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan     fanLCD = map(temp, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD     analogWrite(fan, fanSpeed);  // spin the fan at the fanSpeed speed   }   if(temp > tempMax) {        // if temp is higher than tempMax     digitalWrite(led, HIGH);  // turn on led   }   else {                    // else turn of led     digitalWrite(led, LOW);   }   lcd.print("TEMP: ");   lcd.print(temp);      // display the temperature   lcd.print("C ");   lcd.setCursor(0,1);   // move cursor to next line   lcd.print("FANS: ");   lcd.print(fanLCD);    // display the fan speed   lcd.print("%");   delay(200);   lcd.clear();   } float readTemp() {  // get the temperature and convert it to celsius   temp = analogRead(tempPin);   return temp * 0.48828125; } void loop() {    ultrasonic();   heat(); }

Question by Melromeo    |  last reply

### Arduino | Run 2 Function at the same time.

Hi , i wanna ask about 2 function which is Ultrasonic and Heat that run at the same time  , For me , i just got Heat running as i want but the Ultrasonic doesn't trigger the buzzer if object (Laptop) 30cm away from the ultrasonic. I've been trying since last week but the result is still the same ;'( Btw here is the code , i've seperate it to 2 function which is Ultrasonic and Heat.  i hope u guys can guide me which part should i change or Add. Thanks in advance ;) //*********************************** #include #define trigPin 6    //trigPin #define echoPin 7    //echoPin LiquidCrystal lcd(12,11,5,4,3,2); int tempPin = A1;   // the output pin of LM35 int fan = 10;       // the pin where fan is int led = 9;        // led pin int temp; int tempMin = 35;   // the temperature to start the fan int tempMax = 70;   // the maximum temperature when fan is at 100% int fanSpeed; int fanLCD; int duration, distance; int buzzer = LOW; void setup() {   Serial.begin (9600);        //Baud rate   pinMode (trigPin, OUTPUT);  //trig pin as output   pinMode (echoPin, INPUT);   //echo pin as input   pinMode (13, OUTPUT);       //Buzzer pin as output   pinMode(fan, OUTPUT);   pinMode(led, OUTPUT);   pinMode(tempPin, INPUT);   lcd.begin(16,2);   } void ultrasonic() {   digitalWrite (trigPin, HIGH);   delayMicroseconds (1000);   digitalWrite (trigPin, LOW);   duration = pulseIn (echoPin, HIGH);   distance = (duration/2) / 29.1;   if (distance > 30)   {     Serial.print(distance);     Serial.println(" cm");     digitalWrite (13, HIGH);   }   else   {     Serial.println (distance);     Serial.println ( "cm");     digitalWrite (13, LOW);   } } void heat() {   temp = readTemp();     // get the temperature   if(temp < tempMin) {   // if temp is lower than minimum temp     fanSpeed = 0;      // fan is not spinning     digitalWrite(fan, LOW);         }   if((temp >= tempMin) && (temp <= tempMax)) {  // if temperature is higher than minimum temp     fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan     fanLCD = map(temp, tempMin, tempMax, 0, 100);  // speed of fan to display on LCD     analogWrite(fan, fanSpeed);  // spin the fan at the fanSpeed speed   }   if(temp > tempMax) {        // if temp is higher than tempMax     digitalWrite(led, HIGH);  // turn on led   }   else {                    // else turn of led     digitalWrite(led, LOW);   }   lcd.print("TEMP: ");   lcd.print(temp);      // display the temperature   lcd.print("C ");   lcd.setCursor(0,1);   // move cursor to next line   lcd.print("FANS: ");   lcd.print(fanLCD);    // display the fan speed   lcd.print("%");   delay(200);   lcd.clear();   } float readTemp() {  // get the temperature and convert it to celsius   temp = analogRead(tempPin);   return temp * 0.48828125; } void loop() {    ultrasonic();   heat(); } //***********************************

Topic by Melromeo    |  last reply

### Why or why not does .9 repeating equal 1?

I already posted this as a regular question, but someone told me to make it as a burning question, so here it is: HI! I am wondering if .999...=1? I mean if 1/3=.333 and 1/3+1/3+1/3=3/3 and 3/3=1. So wouldn't .333...+.333...+.333...=1? But it actually equals .999... not 1. I googled this question and I got many different answers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For example...(someone wrote): I'm not really into math, but a friend brought something up to me today that really seemed very strange. (For the duration of this post, .999 will mean .9 repeating unless otherwise specified- just for the sake of ease) .999=x 10x=9.999 10x - x = 9x 9x=9 1x=1. .999 = 1. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Someone else wrote: Numbers are fake. They are a manifestation of our minds to describe something, similar to words. Just because we say "red" doesn't mean something is red. what is red? Languages and math are very similar. Math is universal...at least for our planet though. .999~ does not = 1. But what .999~ repeating represents, does in fact equal what 1 represents. No-one will ever be able to comprehend infinity, os its time to stop trying. Think of space and the universe. IT IS GROWING. how can it continue to grow with no stop? what is there to contain it? WE need something to contain it in order for us to understand it. We need a stopping point, but there is none. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Another person wrote: In your proof that .333...*3=.999... you forgot to include the fact that .3333... is NOT 1/3. 1/3 if not a number that can be turned into a decimal in any way. I thought someone might like to know this fact. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And the last person wrote: Just a pedantic point the equation for differentiation is given by lim x->0 [f(x+h)-f(x)]/h, it has the minus sign. It is after all just telling you the slope and is no different really from doing simple trig using the tan function. Here you just take a really small triangle. As to the 0.99~ thing, this is really just writing the supremum (spelling might be off) of the numbers less than 1. Just think of it as taking the smallest number 'n-word' than 0 away from 1. They are not identical for if they were we would not have a continuous number line, but rather a dashed one with lots of wholes in it. I could simply argue that 0.99~8 is just as close to 0.99~9 as 0.99~ is to 1. For those who really want to understand go and look up supremum numbers and the axioms of the real number line. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ So who is correct? Do you agree that .999...=1? Or .999... does not equal 1?

Topic by Pizzapie500    |  last reply

### Write output on registery inside ESP8266

Could any one help me please? I have the following code to make MODBUS tcp/ip(its work good) the other issue in the code is ultrasonic sensor (trig on D1& echo on D2 and output distance on serial port)I want to write distance on one of memory register say (3). I use the command "digitalWrite(distance, MBHoldingRegister[3] )" its fail then I use analogWrite also fail what's the solution?#include #define trigPin D1#define echoPin D2#define analog_output D5float distance;long duration;int dataIn;int m = 0;int h = 0;int t = 0;const char* ssid = "MH_Ext";const char* password = "74375325";int ModbusTCP_port = 502;//////// Required for Modbus TCP / IP /// Requerido para Modbus TCP/IP /////////#define maxInputRegister 20#define maxHoldingRegister 20#define MB_FC_NONE 0#define MB_FC_READ_REGISTERS 3 //implemented#define MB_FC_WRITE_REGISTER 6 //implemented#define MB_FC_WRITE_MULTIPLE_REGISTERS 16 //implemented// MODBUS Error Codes//#define MB_EC_NONE 0#define MB_EC_ILLEGAL_FUNCTION 1#define MB_EC_ILLEGAL_DATA_ADDRESS 2#define MB_EC_ILLEGAL_DATA_VALUE 3#define MB_EC_SLAVE_DEVICE_FAILURE 4// MODBUS MBAP offsets//#define MB_TCP_TID 0#define MB_TCP_PID 2#define MB_TCP_LEN 4#define MB_TCP_UID 6#define MB_TCP_FUNC 7#define MB_TCP_REGISTER_START 8#define MB_TCP_REGISTER_NUMBER 10byte ByteArray[260];unsigned int MBHoldingRegister[maxHoldingRegister];//////////////////////////////////////////////////////////////////////////WiFiServer MBServer(ModbusTCP_port);void setup() {pinMode(14, OUTPUT);pinMode(trigPin, OUTPUT);pinMode(echoPin, INPUT);Serial.begin(9600);delay(100) ;WiFi.begin(ssid, password);delay(100) ;Serial.println(".");while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}MBServer.begin();Serial.println("Connected ");Serial.print("ESP8266 Slave Modbus TCP/IP ");Serial.print(WiFi.localIP());Serial.print(":");Serial.println(String(ModbusTCP_port));Serial.println("Modbus TCP/IP Online");}void loop() {distance = getDistance();Serial.println(distance);delay(1000);// Check if a client has connected // Modbus TCP/IPWiFiClient client = MBServer.available();if (!client) {return;}boolean flagClientConnected = 0;byte byteFN = MB_FC_NONE;int Start;int WordDataLength;int ByteDataLength;int MessageLength;// Modbus TCP/IPwhile (client.connected()) {if(client.available()){flagClientConnected = 1;int i = 0;while(client.available()){ByteArray[i] = client.read();i++;}client.flush();///// code here --- codigo aqui///////// Holding Register [0] A [9] = 10 Holding Registers Escritura///////// Holding Register [0] A [9] = 10 Holding Registers Writing/// Enable Output 14digitalWrite(14, MBHoldingRegister[14] );digitalWrite(distance, MBHoldingRegister[12] );//// end code - fin//// rutine Modbus TCPbyteFN = ByteArray[MB_TCP_FUNC];Start = word(ByteArray[MB_TCP_REGISTER_START],ByteArray[MB_TCP_REGISTER_START+1]);WordDataLength = word(ByteArray[MB_TCP_REGISTER_NUMBER],ByteArray[MB_TCP_REGISTER_NUMBER+1]);}// Handle requestswitch(byteFN) {case MB_FC_NONE:break;case MB_FC_READ_REGISTERS: // 03 Read Holding RegistersByteDataLength = WordDataLength * 2;ByteArray[5] = ByteDataLength + 3; //Number of bytes after this one.ByteArray[8] = ByteDataLength; //Number of bytes after this one (or number of bytes of data).for(int i = 0; i < WordDataLength; i++){ByteArray[ 9 + i * 2] = highByte(MBHoldingRegister[Start + i]);ByteArray[10 + i * 2] = lowByte(MBHoldingRegister[Start + i]);}MessageLength = ByteDataLength + 9;client.write((const uint8_t *)ByteArray,MessageLength);byteFN = MB_FC_NONE;break;case MB_FC_WRITE_REGISTER: // 06 Write Holding RegisterMBHoldingRegister[Start] = word(ByteArray[MB_TCP_REGISTER_NUMBER],ByteArray[MB_TCP_REGISTER_NUMBER+1]);ByteArray[5] = 6; //Number of bytes after this one.MessageLength = 12;client.write((const uint8_t *)ByteArray,MessageLength);byteFN = MB_FC_NONE;break;case MB_FC_WRITE_MULTIPLE_REGISTERS: //16 Write Holding RegistersByteDataLength = WordDataLength * 2;ByteArray[5] = ByteDataLength + 3; //Number of bytes after this one.for(int i = 0; i < WordDataLength; i++){MBHoldingRegister[Start + i] = word(ByteArray[ 13 + i * 2],ByteArray[14 + i * 2]);}MessageLength = 12;client.write((const uint8_t *)ByteArray,MessageLength);byteFN = MB_FC_NONE;break;}}}//===== getDistance - Custom Functionint getDistance() {// Clears the trigPindigitalWrite(trigPin, LOW);delayMicroseconds(2);// Sets the trigPin on HIGH state for 10 micro secondsdigitalWrite(trigPin, HIGH);delayMicroseconds(10);digitalWrite(trigPin, LOW);// Reads the echoPin, returns the sound wave travel time in microsecondsduration = pulseIn(echoPin, HIGH);// Calculating the distancedistance = duration * 0.034 / 2; // distance in cmreturn distance;}

Question by methaq_ali

### new to arduino, want to run a dual display for 2 sensors

I'm new to the Arduino community.  wanting to set up a dual radar setup with 2 ultrasonic sensors,  (Ultrasonic Sensor Module HC-SR04), and outputting to a pair of 7 segment displays ( two 7 segment displays each).  I've found a code to do a single could use a lot of help to output two at the same time, basically 2 lanes without 2 units.  im using an arduino mega, ordered a unor3 and hopefully it can be made to run on one or the other. code is as follows: /* HC-SR04 Sensor    The circuit:     * VCC connection of the sensor attached to +5V     * GND connection of the sensor attached to ground     * TRIG connection of the sensor attached to digital pin 2     * ECHO connection of the sensor attached to digital pin 4  */    /*  This is a radar ping sensor that calcultates the speed of an  object traveling away or towards the sensor. I took some of this  code for the HC-SR04 Sensor implementation by Tautvidas Sipavicius. The rest  is original code from me. I know that the seven segment display  code is not the best to look at or the most optimized but it  serves its purpose just fine and is easy to understand.    Written by Matthew Ladd  */   const int trigPin = 2; const int echoPin = 4;   void setup() {   // initialize serial communication:   Serial.begin(9600);   //First 7 segment (ones place)   pinMode(30,OUTPUT);//F   pinMode(31,OUTPUT);//G   pinMode(32,OUTPUT);//E   pinMode(33,OUTPUT);//D   pinMode(34,OUTPUT);//C   pinMode(35,OUTPUT);//B   pinMode(36,OUTPUT);//A   //Second 7 segment (tens place)   pinMode(37,OUTPUT);//F   pinMode(38,OUTPUT);//G   pinMode(39,OUTPUT);//E   pinMode(40,OUTPUT);//D   pinMode(41,OUTPUT);//C   pinMode(42,OUTPUT);//B   pinMode(43,OUTPUT);//A } void zerofirst(){   digitalWrite(30,LOW);   digitalWrite(31,HIGH);   digitalWrite(32,LOW);   digitalWrite(33,LOW);   digitalWrite(34,LOW);   digitalWrite(35,LOW);   digitalWrite(36,LOW); } void onefirst(){   digitalWrite(30,HIGH);   digitalWrite(31,HIGH);   digitalWrite(32,HIGH);   digitalWrite(33,HIGH);   digitalWrite(34,LOW);   digitalWrite(35,LOW);   digitalWrite(36,HIGH); } void twofirst(){   digitalWrite(30,HIGH);//F   digitalWrite(31,LOW);//G   digitalWrite(32,LOW);//E   digitalWrite(33,LOW);//D   digitalWrite(34,HIGH);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void threefirst(){   digitalWrite(30,HIGH);//F   digitalWrite(31,LOW);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,LOW);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void fourfirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,HIGH);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,HIGH);//A } void fivefirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,LOW);//D   digitalWrite(34,LOW);//C   digitalWrite(35,HIGH);//B   digitalWrite(36,LOW);//A } void sixfirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,LOW);//E   digitalWrite(33,LOW);//D   digitalWrite(34,LOW);//C   digitalWrite(35,HIGH);//B   digitalWrite(36,LOW);//A } void sevenfirst(){   digitalWrite(30,HIGH);//F   digitalWrite(31,HIGH);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,HIGH);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void eightfirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,LOW);//E   digitalWrite(33,LOW);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void ninefirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,HIGH);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void zerosecond(){   digitalWrite(37,LOW);   digitalWrite(38,HIGH);   digitalWrite(39,LOW);   digitalWrite(40,LOW);   digitalWrite(41,LOW);   digitalWrite(42,LOW);   digitalWrite(43,LOW); } void onesecond(){   digitalWrite(37,HIGH);   digitalWrite(38,HIGH);   digitalWrite(39,HIGH);   digitalWrite(40,HIGH);   digitalWrite(41,LOW);   digitalWrite(42,LOW);   digitalWrite(43,HIGH); } void twosecond(){   digitalWrite(37,HIGH);//F   digitalWrite(38,LOW);//G   digitalWrite(39,LOW);//E   digitalWrite(40,LOW);//D   digitalWrite(41,HIGH);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } void threesecond(){   digitalWrite(37,HIGH);//F   digitalWrite(38,LOW);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,LOW);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } void foursecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,HIGH);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,HIGH);//A } void fivesecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,LOW);//D   digitalWrite(41,LOW);//C   digitalWrite(42,HIGH);//B   digitalWrite(43,LOW);//A } void sixsecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,LOW);//E   digitalWrite(40,LOW);//D   digitalWrite(41,LOW);//C   digitalWrite(42,HIGH);//B   digitalWrite(43,LOW);//A } void sevensecond(){   digitalWrite(37,HIGH);//F   digitalWrite(38,HIGH);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,HIGH);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } void eightsecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,LOW);//E   digitalWrite(40,LOW);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } void ninesecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,HIGH);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } long distanceOverTime(long first,long second){  return ((first-second)/.1)*.0223693629;//taking cm/s to mph } long holder;//store the cm from last time through loop. long temp;//used to store the speed value after changes int counter; void loop() {   // establish variables for duration of the ping,   // and the distance result in inches and centimeters:   long duration, inches, cm;   int tens;   int ones;   long Speed;   // The sensor is triggered by a HIGH pulse of 10 or more microseconds.   // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:   pinMode(trigPin, OUTPUT);   digitalWrite(trigPin, LOW);   delayMicroseconds(2);   digitalWrite(trigPin, HIGH);   delayMicroseconds(10);   digitalWrite(trigPin, LOW);     // Read the signal from the sensor: a HIGH pulse whose   // duration is the time (in microseconds) from the sending   // of the ping to the reception of its echo off of an object.   pinMode(echoPin, INPUT);   duration = pulseIn(echoPin, HIGH);     // convert the time into a distance   inches = microsecondsToInches(duration);   cm = microsecondsToCentimeters(duration);   Speed=distanceOverTime(holder,cm);   holder=cm;//after speed caclulation so take the cm value for another calculation   Speed=abs(Speed);   if(Speed!=0 || counter==10){     temp=Speed;     counter=0;   }else{     counter++;   }   if(temp>=100){    zerofirst();    zerosecond();   }else{     ones=temp%10;     tens=temp/10;   }   if(ones == 0){     zerofirst();   }else if(ones==1){     onefirst();   }else if(ones==2){     twofirst();   }else if(ones==3){     threefirst();   }else if(ones==4){     fourfirst();   }else if(ones==5){     fivefirst();   }else if(ones==6){     sixfirst();   }else if(ones==7){     sevenfirst();   }else if(ones==8){     eightfirst();   }else if(ones==9){     ninefirst();   }   if(tens == 0){     zerosecond();   }else if(tens==1){     onesecond();   }else if(tens==2){     twosecond();   }else if(tens==3){     threesecond();   }else if(tens==4){     foursecond();   }else if(tens==5){     fivesecond();   }else if(tens==6){     sixsecond();   }else if(tens==7){     sevensecond();   }else if(tens==8){     eightsecond();   }else if(tens==9){     ninesecond();   }       Serial.print(inches);   Serial.print(" in, ");   Serial.print(cm);   Serial.print(" cm, ");   Serial.print(Speed);   Serial.print(" mph");   Serial.println();     delay(100); }   long microsecondsToInches(long microseconds) {   // According to Parallax's datasheet for the PING))), there are   // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per   // second).  This gives the distance travelled by the ping, outbound   // and return, so we divide by 2 to get the distance of the obstacle.   // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf   return microseconds / 74 / 2; }   long microsecondsToCentimeters(long microseconds) {   // The speed of sound is 340 m/s or 29 microseconds per centimeter.   // The ping travels out and back, so to find the distance of the   // object we take half of the distance travelled.   return microseconds / 29 / 2; } again, all your help and thought are appricated

Topic by herb1977    |  last reply