// Easy button Version 1.0 // Code writen by Matthew Varian www.3too1.com // Free for distrubution and use byte RED = 15; //red on pin 15 byte BLUE = 12; //blue on pin 12 byte GREEN = 14; //Green on pin 14 byte COLORS[] = {RED, BLUE, GREEN}; boolean on = true; int i = 0; int max = 2; // max number of menue options you want change to whatever you want int min = 0; // min number of menue options you want(leave at zero) int up =0; int down=0; #define encoder0PinA 6 #define encoder0PinB 7 #define BOUNCE_DURATION 100 // define an appropriate bounce time in ms for your encoder volatile unsigned long bounceTime=0; // variable to hold ms count to debounce a pressed switch volatile unsigned int encoder0Pos = 0; int menue=min+1; int EasyButton0 = 20; int EasyButton1 = 21; int buttonState = 0; void setup() { pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT); pinMode(encoder0PinA, INPUT); digitalWrite(encoder0PinA, HIGH); // turn on pullup resistor pinMode(encoder0PinB, INPUT); digitalWrite(encoder0PinB, HIGH); // turn on pullup resistor attachInterrupt(1, intHandler1, CHANGE); pinMode(EasyButton0,INPUT_PULLUP); pinMode(EasyButton1,OUTPUT); digitalWrite(EasyButton1, LOW); } void loop() { if(up==1) { if (menue ==max) menue=min; else menue++; up=0; } if(down==1) { if (menue ==min) menue=max; else menue--; down=0; } switch(menue) { case 0: function0(); break; case 1: function1(); break; case 2: function2(); break; case 3: function3(); break; case 4: function4(); break; case 5: function5(); break; case 6: function6(); break; case 7: function7(); break; case 8: function8(); break; case 9: function9(); break; case 10: function10(); break; } buttonState = !digitalRead(EasyButton0); } void doEncoder() { if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) { up=1; } else { down=1; } } void intHandler1(){ if(millis() > bounceTime) { doEncoder(); bounceTime = millis() + BOUNCE_DURATION; // set whatever bounce time in ms is appropriate } } void function0() //paste { digitalWrite(BLUE, HIGH); if(!digitalRead(EasyButton0)) { // press and hold CTRL Keyboard.set_modifier(MODIFIERKEY_CTRL); Keyboard.send_now(); Keyboard.set_key1(KEY_V); Keyboard.send_now(); // release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key1(0); Keyboard.send_now(); delay(800); } digitalWrite(BLUE, LOW); } void function1() { digitalWrite(RED, HIGH); if(!digitalRead(EasyButton0)) { int l; for (l=0; l<40; l++) { Mouse.move(-10, 0); delay(25); } for (l=0; l<40; l++) { Mouse.move(10, 0); delay(25); } } digitalWrite(RED, LOW); } void function2() //copy { digitalWrite(GREEN, HIGH); if(!digitalRead(EasyButton0)) { Keyboard.set_modifier(MODIFIERKEY_CTRL); Keyboard.send_now(); Keyboard.set_key1(KEY_C); Keyboard.send_now(); // release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key1(0); Keyboard.send_now(); delay(800); } digitalWrite(GREEN, LOW); } void function3() { } void function4() { } void function5() { } void function6() { } void function7() { } void function8() { } void function9() { } void function10() { }