Hi,
I am quite new with launchpad and Energia and I am trying to code that when I point with my remote control at the IR receiver my two Servo motors will go to a specific point and repeat over and over again, but when I press the same button again they will stop moving. So I got 5 buttons on my small remote control and I want them to each play a different command. I already made something, but the problem with that is that the servo's won't stop moving. Can someone please help me with this? :)
-
#include <IRremote.h>#include <Servo.h>Servo motorA; //the name of the servo motorServo motorB;IRrecv irrecv(7); // the receiver connected with pin 7decode_results results;void setup(){Serial.begin(9600); //serial communicationirrecv.enableIRIn(); // start the receiverpinMode(GREEN_LED,OUTPUT);digitalWrite(GREEN_LED,HIGH);digitalWrite(RED_LED,HIGH);motorA.attach(13); // connect the servo with pin 13 and 10motorB.attach(10);}void loop(){if (irrecv.decode(&results)) {Serial.print("IR code: ");Serial.println(results.value, HEX);int key = results.value % 16;Serial.print("key: ");Serial.println(key);switch (key){case 2:doKey2();break;case 3:doKey3();break;case 4:doKey4();break;case 7:doKey7();break;case 8:doKey8();break;}
-
}}void doKey2(){ //DOWN button on remote controldigitalWrite(GREEN_LED,LOW);delay(300);digitalWrite(GREEN_LED,HIGH);motorA.write(0);motorB.write(160);}void doKey3(){ //STROBE button on remote controldigitalWrite(GREEN_LED,LOW);delay(300);digitalWrite(GREEN_LED,HIGH);motorA.write(88);motorB.write(126);delay(400);motorA.write(10);motorB.write(120);}void doKey4(){ //SPEED button on remote controldigitalWrite(RED_LED,LOW);delay(300);digitalWrite(RED_LED,HIGH);motorA.write(49);motorB.write(160);delay(1000);motorA.write(13);motorB.write(93);}void doKey7(){ //SELECT button on remote controldigitalWrite(GREEN_LED,LOW);delay(300);digitalWrite(GREEN_LED,HIGH);motorA.write(90);motorB.write(179);delay(800);motorA.write(138);motorB.write(5);}void doKey8(){ //UP button on remote controldigitalWrite(RED_LED,LOW);delay(300);digitalWrite(RED_LED,HIGH);motorA.write(78);motorB.write(120);delay(300);motorA.write(130);motorB.write(12);}void flashLed(int nr){Serial.print("Flashled: ");}