Question: Help me debug my adruino code /////////CODE BEGINS////////////unsigned long signal_len,t1,t2; //time for which button is pressedint inputPin = 2; //input pin for push buttonint ledPin
Help me debug my adruino code
/////////CODE BEGINS////////////unsigned long signal_len,t1,t2; //time for which button is pressedint inputPin = 2; //input pin for push buttonint ledPin = 4; //output pin for LEDString code = "";int num; int memory[2];void setup(){Serial.begin(9600);pinMode(inputPin, INPUT_PULLUP); //internal pullup resistor is used to simplify the circuitpinMode(ledPin,OUTPUT);}int counter=0;void loop(){NextDotDash:while (digitalRead(inputPin) == HIGH) {}t1 = millis(); //time at button pressdigitalWrite(ledPin, HIGH); //LED on while button pressedwhile (digitalRead(inputPin) == LOW) {}t2 = millis(); //time at button releasedigitalWrite(ledPin, LOW); //LED off on button releasesignal_len = t2 - t1; //time for which button is pressedif (signal_len > 50) //to account for switch debouncing{code += readio(); //function to read dot or dash}while ((millis() - t2) 0&&num 50){return '.'; //if button press less than 0.2sec, it is a dot}else if (signal_len > 200){return '-'; //if button press more than 0.2sec, it is a dash}}void convertor(){static String letters[] = {"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--....", "---..", "----.", "E"};int i = 0;if (code == ".-.-.-"){Serial.print("."); //for break}else{while (letters[i] != "E") //loop for comparing input code with letters array{if (letters[i] == code){num=0+i;Serial.print(num);break;}else num=10;i++;}if (letters[i] == "E"){Serial.println(""); //if input code doesn't match any number, error}}code = ""; //reset code to blank}//////////CODE ENDS//////////////////////Code PART BThis code is the full code in Part A with the substraction function implemented as well:////////////PART B CODE BEGINS//////////////unsigned long signal_len,t1,t2; //time for which button is pressedint inputPin = 2; //input pin for push buttonint ledPin = 4; //outpu pin for LEDString code = "";int num;int memory[2];bool add=true;void setup(){Serial.begin(9600);pinMode(inputPin, INPUT_PULLUP); //internal pullup resistor is used to simplify the circuitpinMode(ledPin,OUTPUT);}int counter=0;void loop(){NextDotDash:while (digitalRead(inputPin) == HIGH) {}t1 = millis(); //time at button pressdigitalWrite(ledPin, HIGH); //LED on while button pressedwhile (digitalRead(inputPin) == LOW) {}t2 = millis(); //time at button releasedigitalWrite(ledPin, LOW); //LED off on button releasesignal_len = t2 - t1; //time for which button is pressedif (signal_len > 50) //to account for switch debouncing{code += readio(); //function to read dot or dash}while ((millis() - t2) 0&&num 50){return '.'; //if button press less than 0.6sec, it is a dot}else if (signal_len > 200&&signal_len 1200){ return 'x';}}void convertor(){static String letters[] = {"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--....", "---..", "----.","x", "E"};int i = 0;if (code == ".-.-.-"){Serial.print("."); //for break}else{while (letters[i] != "E") //loop for comparing input code with letters array{if (letters[i] == code){num=0+i;if(num
\f\f Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
