Advertisement
crabbypup

Media Keys

Nov 7th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. const int Row[2] = { 2, 1 };          // initialize the row and column pins
  2.  
  3. const int Col[3] = { 3, 4, 0 };
  4.  
  5. int c1 = 1; // set up vars for the column states
  6. int c2 = 1;
  7. int c3 = 1;
  8.  
  9. void setup() {
  10.   // set modes of rows and columns
  11.   pinMode(Row[0], OUTPUT);
  12.   pinMode(Row[1], OUTPUT);
  13.  
  14.   pinMode(Col[0], INPUT);
  15.   pinMode(Col[1], INPUT);
  16.   pinMode(Col[2], INPUT);
  17.  
  18.   digitalWrite(Col[0], HIGH); //enable the internal pull up resistors
  19.   digitalWrite(Col[1], HIGH);
  20.   digitalWrite(Col[2], HIGH);
  21.  
  22. }
  23.  
  24. void loop() {
  25.   digitalWrite(Row[0], LOW); //pull low the row we are querying
  26.   digitalWrite(Row[1], HIGH);
  27.  
  28.   c1 = digitalRead(Col[0]); //grab button states
  29.   c2 = digitalRead(Col[1]);
  30.   c3 = digitalRead(Col[2]);
  31.  
  32.   if (c1 == LOW) {
  33.     Remote.decrease();
  34.     Remote.clear(); //reset the key state to prevent repeating keys
  35.     c1 = 1;
  36.     delay(200); //debounce
  37.   }
  38.  
  39.   else if (c2 == LOW) {
  40.     Remote.mute();
  41.     Remote.clear();
  42.     c2 = 1;
  43.     delay(200);
  44.   }
  45.  
  46.   else if (c3 == LOW) {
  47.     Remote.increase();
  48.     Remote.clear();
  49.     c3 = 1;
  50.     delay(200);
  51.   }
  52.  
  53.   digitalWrite(Row[0], HIGH); //select the other row
  54.   digitalWrite(Row[1], LOW);
  55.  
  56.   c1 = digitalRead(Col[0]);
  57.   c2 = digitalRead(Col[1]);
  58.   c3 = digitalRead(Col[2]);
  59.  
  60.   if (c1 == LOW) {
  61.     Remote.previous();
  62.     Remote.clear();
  63.     c1 = 1;
  64.     delay(200);
  65.   }
  66.  
  67.   else if (c2 == LOW) {
  68.     Remote.TogglePlay();
  69.     Remote.clear();
  70.     c2 = 1;
  71.     delay(200);
  72.   }
  73.  
  74.   else if (c3 == LOW) {
  75.     Remote.next();
  76.     Remote.clear();
  77.     c3 = 1;
  78.     delay(200);
  79.   }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement