Advertisement
geovannefarell

arduino uno

Jul 19th, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. // Remote Control
  2.  
  3. //Use of 4 pins, 2 for channel changes, 2 volume changes
  4. int ChannelPlusPin = 5;
  5. int ChannelLessPin = 6;
  6. int VolumePlusPin = 7;
  7. int VolumeLessPin = 8;
  8.  
  9.  
  10. int pulse = 25000;   // milliseconds to hold button on
  11.  
  12.  
  13. void setup()
  14. {
  15.   //set up pins as outputs
  16.  
  17.  
  18.   pinMode(ChannelPlusPin, OUTPUT);
  19.   pinMode(ChannelLessPin, OUTPUT);
  20.   pinMode(VolumePlusPin, OUTPUT);
  21.   pinMode(VolumeLessPin, OUTPUT);
  22.  
  23.   Serial.begin(9600);// Start serial communication at 9600 bps
  24.  
  25. }
  26.  
  27. // function for updating any pin
  28.    void updatePin (int pin, int pulse){
  29.   Serial.print("RECEIVED PIN");
  30.   Serial.println(pin); 
  31.   digitalWrite(pin, LOW);
  32.   delayMicroseconds(pulse);
  33.   digitalWrite(pin, HIGH);
  34.   Serial.println("ON");
  35.   Serial.println("OFF");
  36. }
  37. void loop()
  38. {
  39.  /* while(1){
  40.   digitalWrite(5, HIGH);  
  41.   digitalWrite(6, HIGH);
  42.   digitalWrite(7, HIGH);
  43.   digitalWrite(8, HIGH);
  44.   }*/  
  45.   if (Serial.available()) { // If data is available to read,
  46.     char val=Serial.read();
  47.      if(val == '1') {
  48.       // Channel plus button pulsed
  49.        
  50.       digitalWrite(5, LOW);  
  51.   digitalWrite(6, HIGH);
  52.   digitalWrite(7, HIGH);
  53.   digitalWrite(8, HIGH);
  54.   delay(250);
  55.   digitalWrite(5, HIGH);  
  56.   digitalWrite(6, HIGH);
  57.   digitalWrite(7, HIGH);
  58.   digitalWrite(8, HIGH);
  59.   delay(250);
  60.   digitalWrite(5, LOW);  
  61.   digitalWrite(6, LOW);
  62.   digitalWrite(7, LOW);
  63.   digitalWrite(8, LOW);
  64.   delay(250);
  65.   updatePin(ChannelPlusPin, pulse);
  66.     } else if(val == '2') {
  67.       // Channel less button pulsed
  68.      
  69.      digitalWrite(5, HIGH);  
  70.   digitalWrite(6, LOW);
  71.   digitalWrite(7, HIGH);
  72.   digitalWrite(8, HIGH);
  73.   delay(250);
  74.   digitalWrite(5, HIGH);  
  75.   digitalWrite(6, HIGH);
  76.   digitalWrite(7, HIGH);
  77.   digitalWrite(8, HIGH);
  78.   delay(250);
  79.   digitalWrite(5, LOW);  
  80.   digitalWrite(6, LOW);
  81.   digitalWrite(7, LOW);
  82.   digitalWrite(8, LOW);
  83.   delay(250);
  84.   updatePin(ChannelLessPin, pulse);
  85.     } else if(val == '3') {
  86.       // Volume plus button pulsed
  87.      
  88.    digitalWrite(5, HIGH);  
  89.   digitalWrite(6, HIGH);
  90.   digitalWrite(7, LOW);
  91.   digitalWrite(8, HIGH);
  92.   delay(1000);
  93.   digitalWrite(5, HIGH);  
  94.   digitalWrite(6, HIGH);
  95.   digitalWrite(7, HIGH);
  96.   digitalWrite(8, HIGH);
  97.   delay(250);
  98.   digitalWrite(5, LOW);  
  99.   digitalWrite(6, LOW);
  100.   digitalWrite(7, LOW);
  101.   digitalWrite(8, LOW);
  102.   delay(250);
  103.   updatePin(VolumePlusPin, pulse);
  104.  
  105.   } else if(val == '4') {
  106.       // Volume less button pulsed
  107.      
  108.    digitalWrite(5, HIGH);  
  109.   digitalWrite(6, HIGH);
  110.   digitalWrite(7, HIGH);
  111.   digitalWrite(8, LOW);
  112.   delay(1000);
  113.   digitalWrite(5, HIGH);  
  114.   digitalWrite(6, HIGH);
  115.   digitalWrite(7, HIGH);
  116.   digitalWrite(8, HIGH);
  117.   delay(250);
  118.   digitalWrite(5, LOW);  
  119.   digitalWrite(6, LOW);
  120.   digitalWrite(7, LOW);
  121.   digitalWrite(8, LOW);
  122.   delay(250);
  123.   updatePin(VolumeLessPin, pulse);
  124.   }  
  125.    }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement