0

I have a rotary switch I want to use with my teensy 3.2. I have this code:

#include <Bounce.h>
Bounce button3 = Bounce(3, 10);   // Key 'Q'
Bounce button4 = Bounce(4, 10);   // Key 'W'
Bounce button5 = Bounce(5, 10);   // Key 'E'
Bounce button6 = Bounce(6, 10);   // Key 'R'
Bounce button7 = Bounce(7, 10);   // Key 'T'

int modeNum;

void setup() {
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP); 
pinMode(7, INPUT_PULLUP);
}

void loop {

button3.update();
button4.update();
button5.update();
button6.update();
button7.update();

 if (button3.read() == LOW)
 {
  if (modeNum != 1)
  {
    modeNum = 1;
    usb_keyboard_press(KEY_Q, 0);
  }
 }
 else if (button4.read() == LOW)
 {
  if (modeNum != 2)
  {
   modeNum = 2;
   usb_keyboard_press(KEY_W, 0);
  }
 }
 else if (button5.read() == LOW)
 {
   if (modeNum != 3)
   {
     modeNum = 3;
     usb_keyboard_press(KEY_E, 0);
   }
 }
 else if (button6.read() == LOW)
 {
   if (modeNum != 4)
   {
     modeNum = 4;
     usb_keyboard_press(KEY_R, 0);
   }
 }
 else if (button7.read() == LOW)
 {
   if (modeNum != 5)
   {
     modeNum = 5;
     usb_keyboard_press(KEY_T, 0);
   }
 }
}

I have it initialized correctly. And I have the rotary encoder wired correctly. I just don't know why my code isn't sending keystrokes when I rotate my dial.

ShadowWesley77
  • 365
  • 1
  • 5
  • 16
  • With this little code or information it's impossible to tell what could be wrong. Have you tried any kind of debugging? For example printing out (through the serial line or other way) what values you get from the switch, or what functions you call? – Some programmer dude Oct 31 '15 at 14:46
  • What more information do you you need? i have the rest of my program here but I'm unsure as to what you need to see whats wrong – ShadowWesley77 Oct 31 '15 at 14:48
  • Focus on one switch, pin 3 for example, Check the wire, check if you detect the press on with dummy sketch. Then if everything is ok, add debui into your code. – Ôrel Nov 01 '15 at 21:42
  • The rotary switch is five switches connected to ground, right? Use a simple sketch (with serial output, preferably) and then, please, initialize the `modeNum` variable.... – frarugi87 Nov 04 '15 at 17:06

0 Answers0