#include // Infrared receiving pin int RECV_PIN = 12; // DC driver MOTOR #define ENABLE 5 #define DIRA 3 #define DIRB 4 // Define a variable to save the motor rotation speed int rotationSpeed = 0; // Comandi IR long ir_zero = 16738455; long ir_uno = 16724175; long ir_due = 16718055; long ir_tre = 16743045; long ir_quattro = 16716015; long ir_cinque = 16726215; long ir_sei = 16734885; long ir_sette = 16728765; long ir_otto = 16730805; long ir_nove = 16732845; long ir_start = 16753245; long ir_stop = 16712445; long ir_piu = 16736925; long ir_meno = 16754775; IRrecv irrecv(RECV_PIN); // Create a class object used to receive class decode_results results; // Create a decoding results class object void setup() { Serial.begin(9600); // Initialize the serial port and set the baud rate to 9600 // Start the receiver irrecv.enableIRIn(); //DC driver set pin direction pinMode(ENABLE,OUTPUT); pinMode(DIRA,OUTPUT); pinMode(DIRB,OUTPUT); } void loop() { // Attendo comando da telecomando IR if (irrecv.decode(&results)) { // Waiting for decoding //Serial.println(results.value); // Print out the decoded results rotationSpeed = 0; if (results.value == ir_zero) { Serial.println("ZERO"); rotationSpeed = 0; } else if (results.value == ir_uno) { Serial.println("UNO"); rotationSpeed = round(255 * 0.1); // velocità 0-255 } else if (results.value == ir_due) { Serial.println("DUE"); rotationSpeed = round(255 * 0.2); // velocità 0-255 } else if (results.value == ir_tre) { Serial.println("TRE"); rotationSpeed = round(255 * 0.3); // velocità 0-255 } else if (results.value == ir_quattro) { Serial.println("QUATTRO"); rotationSpeed = round(255 * 0.4); // velocità 0-255 } else if (results.value == ir_cinque) { Serial.println("CINQUE"); rotationSpeed = round(255 * 0.5); // velocità 0-255 } else if (results.value == ir_sei) { Serial.println("SEI"); rotationSpeed = round(255 * 0.6); // velocità 0-255 } else if (results.value == ir_sette) { Serial.println("SETTE"); rotationSpeed = round(255 * 0.7); // velocità 0-255 } else if (results.value == ir_otto) { Serial.println("OTTO"); rotationSpeed = round(255 * 0.8); // velocità 0-255 } else if (results.value == ir_nove) { Serial.println("NOVE"); rotationSpeed = round(255 * 0.9); // velocità 0-255 } irrecv.resume(); // Receive the next value } //---PWM example, full speed then slow analogWrite(ENABLE,rotationSpeed); //enable on digitalWrite(DIRA,HIGH); //one way digitalWrite(DIRB,LOW); delay(100); }