I building an led macro pad using a promicro. I uploaded the code i am using and it started to press all of the buttons even though i don’t have them connected. I tried uploading the code then holding the promicro in the air as the air
Im using the basic Arduino button circuit.
https://www.arduino.cc/en/uploads/Tutorial/button.png
If you have any questions feel free to ask.
The code:
#include <Keyboard.h>
#include <Adafruit_NeoPixel.h>
#define PIN 9
#define NUMPIXELS 16
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 25;
int delA = 150;
//switches
int but8 = 0;
const int but8pin = 10;
const char *mess8 = "BEANS";
int but7 = 0;
const int but7pin = 16;
const char *mess7 = "Did you ever hear the Tragedy of Darth Plagueis the wise? I thought not. It's not a story the Jedi would tell you. It's a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the midichlorians to create life...";
int but6 = 0;
const int but6pin = 14;
int but5 = 0;
const int but5pin = 15;
const char *mess5 = "Why are we still here? Just to suffer? Every night, I can feel my leg... and my arm... even my fingers. The body I've lost... the comrades I've lost... won't stop hurting... It's like they're all still there. You feel it, too, don't you? I'm gonna make them give back our past.";
int but4 = 0;
const int but4pin = A0;
int but3 = 0;
const int but3pin = A1;
int but2 = 0;
const int but2pin = A2;
int but1 = 0;
const int but1pin = A3;
//Colors
uint32_t on = pixels.Color(255, 0, 255);
uint32_t base0 = pixels.Color(78, 202, 230);
uint32_t base1 = pixels.Color(171, 243, 114);
uint32_t base2 = pixels.Color(255, 241, 42);
uint32_t base3 = pixels.Color(255, 154, 116);
uint32_t base4 = pixels.Color(176, 150, 255);
uint32_t base5 = pixels.Color(80, 204, 225);
uint32_t base6 = pixels.Color(173, 244, 111);
uint32_t base7 = pixels.Color(252, 245, 42);
uint32_t base8 = pixels.Color(255, 186, 84);
uint32_t base9 = pixels.Color(255, 147, 123);
uint32_t base10 = pixels.Color(255, 119, 152);
uint32_t base11 = pixels.Color(255, 74, 198);
uint32_t base12 = pixels.Color(65, 167, 255);
uint32_t base13 = pixels.Color(84, 141, 255);
uint32_t base14 = pixels.Color(123, 103, 255);
uint32_t base15 = pixels.Color(140, 88, 255);
void setup() {
// put your setup code here, to run once:
pinMode(but8pin, INPUT);
pinMode(but7pin, INPUT);
pinMode(but6pin, INPUT);
pinMode(but4pin, INPUT);
pinMode(but3pin, INPUT);
pinMode(but2pin, INPUT);
pinMode(but1pin, INPUT);
Keyboard.begin(); //Init keyboard emulation
pixels.begin();
pixels.setBrightness(75);
pixels.setPixelColor(0,base0);
pixels.setPixelColor(1,base1);
pixels.setPixelColor(2,base2);
pixels.setPixelColor(3,base3);
pixels.setPixelColor(4,base4);
pixels.setPixelColor(5,base5);
pixels.setPixelColor(6,base6);
pixels.setPixelColor(7,base7);
pixels.setPixelColor(8,base8);
pixels.setPixelColor(9,base9);
pixels.setPixelColor(10,base10);
pixels.setPixelColor(11,base11);
pixels.setPixelColor(12,base12);
pixels.setPixelColor(13,base13);
pixels.setPixelColor(14,base14);
pixels.setPixelColor(15,base15);
pixels.show();
}
void loop() {
// put your main code here, to run repeatedly:
but8 = digitalRead(but8pin);
but7 = digitalRead(but7pin);
but6 = digitalRead(but6pin);
but5 = digitalRead(but5pin);
but4 = digitalRead(but4pin);
but3 = digitalRead(but3pin);
but2 = digitalRead(but2pin);
but1 = digitalRead(but1pin);
if(but8 == HIGH){
pixels.setPixelColor(4,on);
pixels.show();
Keyboard.write(' ');
for (int mess8idx = 0; mess8idx < strlen(mess8); mess8idx++){
Keyboard.write(mess8[mess8idx]);
}
Keyboard.releaseAll();
Keyboard.write(' ');
delay(delayval);
pixels.setPixelColor(4,base4);
pixels.show();
}
if(but7 == HIGH){
pixels.setPixelColor(5,on);
pixels.show();
Keyboard.write(' ');
for (int mess7idx = 0; mess7idx < strlen(mess7); mess7idx++){
Keyboard.write(mess7[mess7idx]);
}
Keyboard.write(' ');
delay(delayval);
pixels.setPixelColor(5,base5);
pixels.show();
}
if(but6 == HIGH){
pixels.setPixelColor(6,on);
pixels.show();
Keyboard.write(' ');
delay(delayval);
pixels.setPixelColor(6,base6);
pixels.show();
}
if(but5 == HIGH){
pixels.setPixelColor(7,on);
pixels.show();
Keyboard.write(' ');
for(int mess5idx = 0; mess5idx < strlen(mess5); mess5idx++){
Keyboard.write(mess5[mess5idx]);
}
Keyboard.write(' ');
delay(delayval);
pixels.setPixelColor(7,base7);
pixels.show();
}
if(but4 == HIGH){
pixels.setPixelColor(0,on);
pixels.show();
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_DELETE);
delay(delayval + delA);
Keyboard.releaseAll();
pixels.setPixelColor(0,base0);
pixels.show();
}
if(but3 == HIGH){
pixels.setPixelColor(1,on);
pixels.show();
Keyboard.press(KEY_F15);
delay(delayval + delA);
Keyboard.releaseAll();
pixels.setPixelColor(1,base1);
pixels.show();
}
if(but2 == HIGH){
pixels.setPixelColor(2,on);
pixels.show();
Keyboard.press(KEY_F14);
delay(delayval + delA);
Keyboard.releaseAll();
pixels.setPixelColor(2,base2);
pixels.show();
}
if(but1 == HIGH){
pixels.setPixelColor(3,on);
pixels.show();
Keyboard.press(KEY_F13);
delay(delayval + delA);
Keyboard.releaseAll();
pixels.setPixelColor(3,base3);
pixels.show();
}
/* for(int i=1;i<100;i++){
pixels.setPixelColor(0,pixels.Color(i,0,0));
pixels.show();
delay(100);
} */
}