Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 7th, 2013  |  syntax: C#  |  size: 0.70 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. int pins[] = {0, 1, 2, 3};
  2. int vals[] = {0, 0, 0, 0};
  3. int lastVals[] = {0, 0, 0, 0};
  4. String ch[] = {"a", "d", "s", "w"};
  5.  
  6. long lastDebounceTime[] = {0, 0, 0, 0};
  7. long debounceDelay = 10;
  8.  
  9. void setup() {
  10.  
  11.   for(int i = 0; i < 4; i++)
  12.   {
  13.     pinMode(pins[i], INPUT);
  14.   }
  15. }
  16.  
  17. void loop(){
  18.   for(int i = 0; i < 4; i++)
  19.   {
  20.     int reading = digitalRead(pins[i]);
  21.     if (reading != lastVals[i]) {
  22.       lastDebounceTime[i] = millis();
  23.     }
  24.    
  25.     if ((millis() - lastDebounceTime[i]) > debounceDelay) {
  26.  
  27.     vals[i] = reading;
  28.     }
  29.    
  30.     lastVals[i] = reading;
  31.    
  32.    
  33.     if (vals[i] == HIGH)
  34.     {        
  35.       Keyboard.print(ch[i]);  
  36.     }
  37.   }
  38.   delay(100);
  39. }
clone this paste RAW Paste Data