Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Remote Control
- //Use of 4 pins, 2 for channel changes, 2 volume changes
- int ChannelPlusPin = 5;
- int ChannelLessPin = 6;
- int VolumePlusPin = 7;
- int VolumeLessPin = 8;
- int pulse = 25000; // milliseconds to hold button on
- void setup()
- {
- //set up pins as outputs
- pinMode(ChannelPlusPin, OUTPUT);
- pinMode(ChannelLessPin, OUTPUT);
- pinMode(VolumePlusPin, OUTPUT);
- pinMode(VolumeLessPin, OUTPUT);
- Serial.begin(9600);// Start serial communication at 9600 bps
- }
- // function for updating any pin
- void updatePin (int pin, int pulse){
- Serial.print("RECEIVED PIN");
- Serial.println(pin);
- digitalWrite(pin, LOW);
- delayMicroseconds(pulse);
- digitalWrite(pin, HIGH);
- Serial.println("ON");
- Serial.println("OFF");
- }
- void loop()
- {
- /* while(1){
- digitalWrite(5, HIGH);
- digitalWrite(6, HIGH);
- digitalWrite(7, HIGH);
- digitalWrite(8, HIGH);
- }*/
- if (Serial.available()) { // If data is available to read,
- char val=Serial.read();
- if(val == '1') {
- // Channel plus button pulsed
- digitalWrite(5, LOW);
- digitalWrite(6, HIGH);
- digitalWrite(7, HIGH);
- digitalWrite(8, HIGH);
- delay(250);
- digitalWrite(5, HIGH);
- digitalWrite(6, HIGH);
- digitalWrite(7, HIGH);
- digitalWrite(8, HIGH);
- delay(250);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- digitalWrite(7, LOW);
- digitalWrite(8, LOW);
- delay(250);
- updatePin(ChannelPlusPin, pulse);
- } else if(val == '2') {
- // Channel less button pulsed
- digitalWrite(5, HIGH);
- digitalWrite(6, LOW);
- digitalWrite(7, HIGH);
- digitalWrite(8, HIGH);
- delay(250);
- digitalWrite(5, HIGH);
- digitalWrite(6, HIGH);
- digitalWrite(7, HIGH);
- digitalWrite(8, HIGH);
- delay(250);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- digitalWrite(7, LOW);
- digitalWrite(8, LOW);
- delay(250);
- updatePin(ChannelLessPin, pulse);
- } else if(val == '3') {
- // Volume plus button pulsed
- digitalWrite(5, HIGH);
- digitalWrite(6, HIGH);
- digitalWrite(7, LOW);
- digitalWrite(8, HIGH);
- delay(1000);
- digitalWrite(5, HIGH);
- digitalWrite(6, HIGH);
- digitalWrite(7, HIGH);
- digitalWrite(8, HIGH);
- delay(250);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- digitalWrite(7, LOW);
- digitalWrite(8, LOW);
- delay(250);
- updatePin(VolumePlusPin, pulse);
- } else if(val == '4') {
- // Volume less button pulsed
- digitalWrite(5, HIGH);
- digitalWrite(6, HIGH);
- digitalWrite(7, HIGH);
- digitalWrite(8, LOW);
- delay(1000);
- digitalWrite(5, HIGH);
- digitalWrite(6, HIGH);
- digitalWrite(7, HIGH);
- digitalWrite(8, HIGH);
- delay(250);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- digitalWrite(7, LOW);
- digitalWrite(8, LOW);
- delay(250);
- updatePin(VolumeLessPin, pulse);
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement