You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.3 KiB
101 lines
3.3 KiB
3 years ago
|
#include "/Users/Imogen/Documents/Arduino/libraries/IRremote/IRremote.h"
|
||
|
#include "/Users/Imogen/Documents/Arduino/libraries/IRremote/IRremote.cpp"
|
||
|
#include <Servo.h>
|
||
|
|
||
|
// PIN FOR RECEIVER
|
||
|
int receiver = 3; // Signal Pin of IR receiver to Arduino Digital Pin 11
|
||
|
int pos = 0; // variable to store the servo position
|
||
|
|
||
|
/*-----( Declare objects )-----*/
|
||
|
IRrecv irrecv(receiver); // create instance of 'irrecv'
|
||
|
decode_results results; // create instance of 'decode_results'
|
||
|
Servo myservo; // create servo object to control a servo
|
||
|
|
||
|
/*-----( Function )-----*/
|
||
|
void translateIR() // takes action based on IR code received
|
||
|
|
||
|
// describing Remote IR codes
|
||
|
|
||
|
{
|
||
|
|
||
|
switch (results.value)
|
||
|
{
|
||
|
case 0xFFA25D: Serial.println("POWER"); myservo.attach(9); // attaches the servo on pin 9 to the servo object
|
||
|
break;
|
||
|
case 0xFFE21D: Serial.println("FUNC/STOP"); myservo.detach(); // attaches the servo on pin 9 to the servo object
|
||
|
break;
|
||
|
case 0xFF629D: Serial.println("VOL+"); digitalWrite(8, HIGH); break;
|
||
|
case 0xFF22DD: Serial.println("FAST BACK"); break;
|
||
|
case 0xFF02FD: Serial.println("PAUSE"); break;
|
||
|
case 0xFFC23D: Serial.println("FAST FORWARD"); break;
|
||
|
case 0xFFE01F: Serial.println("DOWN"); for (pos = 5; pos >=0; pos-=1){myservo.attach(9); myservo.write(pos); delay(15); myservo.detach();} break;
|
||
|
case 0xFFA857: Serial.println("VOL-"); digitalWrite(8, LOW); break;
|
||
|
case 0xFF906F: Serial.println("UP"); for (pos = 0; pos <=5; pos+=1){myservo.attach(9); myservo.write(pos); delay(15); myservo.detach();} break;
|
||
|
case 0xFF9867: Serial.println("EQ"); break;
|
||
|
case 0xFFB04F: Serial.println("ST/REPT"); break;
|
||
|
case 0xFF6897: Serial.println("0"); break;
|
||
|
case 0xFF30CF: Serial.println("1"); break;
|
||
|
case 0xFF18E7: Serial.println("2"); break;
|
||
|
case 0xFF7A85: Serial.println("3");; break;
|
||
|
case 0xFF10EF: Serial.println("4"); break;
|
||
|
case 0xFF38C7: Serial.println("5"); break;
|
||
|
case 0xFF5AA5: Serial.println("6"); break;
|
||
|
case 0xFF42BD: Serial.println("7"); break;
|
||
|
case 0xFF4AB5: Serial.println("8"); break;
|
||
|
case 0xFF52AD: Serial.println("9"); break;
|
||
|
//case 0xFFFFFFFF: Serial.println(" REPEAT"); digitalWrite(8, LOW); break;
|
||
|
|
||
|
default:
|
||
|
Serial.println(" other button ");
|
||
|
|
||
|
}// End Case
|
||
|
|
||
|
delay(50); // Do not get immediate repeat
|
||
|
|
||
|
|
||
|
} //END translateIR
|
||
|
|
||
|
|
||
|
|
||
|
//=============================================//
|
||
|
//init all pin used
|
||
|
void setup() {
|
||
|
Serial.begin(9600);
|
||
|
Serial.println("IR Receiver Button Decode - Initializing...");
|
||
|
irrecv.enableIRIn(); // Start the receiver
|
||
|
|
||
|
pinMode(2, OUTPUT);
|
||
|
// pinMode(3, OUTPUT); // reserved for IR input
|
||
|
// pinMode(4, OUTPUT);
|
||
|
// pinMode(5, OUTPUT);
|
||
|
// pinMode(6, OUTPUT);
|
||
|
// pinMode(7, OUTPUT);
|
||
|
pinMode(8, OUTPUT);
|
||
|
pinMode(9, OUTPUT);
|
||
|
myservo.attach(9); // attaches the servo on pin 9 to the servo object
|
||
|
// pinMode(10, OUTPUT);
|
||
|
// pinMode(11, OUTPUT);
|
||
|
// pinMode(12, OUTPUT);
|
||
|
// pinMode(13, OUTPUT);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
//=======================================================================================//
|
||
|
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
|
||
|
{
|
||
|
if (irrecv.decode(&results)) // have we received an IR signal?
|
||
|
{
|
||
|
// Serial.println(results.value); // for debugging
|
||
|
translateIR();
|
||
|
irrecv.resume(); // receive the next value
|
||
|
|
||
|
}
|
||
|
|
||
|
}/* --(end main loop )-- */
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|