So I made a Keyboard try a few weeks ago, but was not happy with the way it turned out. There were a few things that I found that I wanted to add. So this is the next version, added two CAC readers and an audio switcher to be able to choose from headphones or speakers. There is a USB hub inside the tray that powers the three items and an Arduino. The Arduino is used to power and control the lights on the top..
I have attached the code for the Arduino below.
// Blink 8 sets of 4 LEDs per circut at a random interval (1 second to 2.5 seconds) without using delay()
//Curcuit: LEDs connected to pin 13-6, all with 330 ohm resistors to ground.
int led1Pin = 13;
int led2Pin = 12;
int led3Pin = 11;
int led4Pin = 10;
int led5Pin = 9;
int led6Pin = 8;
int led7Pin = 7;
int led8Pin = 6;
int led1State = LOW;
int led2State = LOW;
int led3State = LOW;
int led4State = LOW;
int led5State = LOW;
int led6State = LOW;
int led7State = LOW;
int led8State = LOW;
long previousMillis1 = 0;
long previousMillis2 = 0;
long previousMillis3 = 0;
long previousMillis4 = 0;
long previousMillis5 = 0;
long previousMillis6 = 0;
long previousMillis7 = 0;
long previousMillis8 = 0;
long randInterval1 = 0;
long randInterval2 = 0;
long randInterval3 = 0;
long randInterval4 = 0;
long randInterval5 = 0;
long randInterval6 = 0;
long randInterval7 = 0;
long randInterval8 = 0;
void setup() {
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
pinMode(led4Pin, OUTPUT);
pinMode(led5Pin, OUTPUT);
pinMode(led6Pin, OUTPUT);
pinMode(led7Pin, OUTPUT);
pinMode(led8Pin, OUTPUT);
randomSeed (analogRead (0));
}
void loop()
{
unsigned long currentMillis = millis();
//LED 1/////////////////////////
if(currentMillis - previousMillis1 > randInterval1) {
randInterval1 = random (1000, 2500);
previousMillis1 = currentMillis;
if (led1State == LOW)
led1State = HIGH;
else
led1State = LOW;
digitalWrite(led1Pin, led1State);
}
//LED 2/////////////////////////
if(currentMillis - previousMillis2 > randInterval2) {
randInterval2 = random (1000, 2500);
previousMillis2 = currentMillis;
if (led2State == LOW)
led2State = HIGH;
else
led2State = LOW;
digitalWrite(led2Pin, led2State);
}
//LED 3/////////////////////////
if(currentMillis - previousMillis3 > randInterval3) {
randInterval3 = random (1000, 2500);
previousMillis3 = currentMillis;
if (led3State == LOW)
led3State = HIGH;
else
led3State = LOW;
digitalWrite(led3Pin, led3State);
}
//LED 4/////////////////////////
if(currentMillis - previousMillis4 > randInterval4) {
randInterval4 = random (1000, 2500);
previousMillis4 = currentMillis;
if (led4State == LOW)
led4State = HIGH;
else
led4State = LOW;
digitalWrite(led4Pin, led4State);
}
//LED 5/////////////////////////
if(currentMillis - previousMillis5 > randInterval5) {
randInterval5 = random (1000, 2500);
previousMillis5 = currentMillis;
if (led5State == LOW)
led5State = HIGH;
else
led5State = LOW;
digitalWrite(led5Pin, led5State);
}
//LED 6/////////////////////////
if(currentMillis - previousMillis6 > randInterval6) {
randInterval6 = random (1000, 2500);
previousMillis6 = currentMillis;
if (led6State == LOW)
led6State = HIGH;
else
led6State = LOW;
digitalWrite(led6Pin, led6State);
}
//LED 7/////////////////////////
if(currentMillis - previousMillis7 > randInterval7) {
randInterval7 = random (1000, 2500);
previousMillis7 = currentMillis;
if (led7State == LOW)
led7State = HIGH;
else
led7State = LOW;
digitalWrite(led7Pin, led7State);
}
//LED 8/////////////////////////
if(currentMillis - previousMillis8 > randInterval8) {
randInterval8 = random (1000, 2500);
previousMillis8 = currentMillis;
if (led8State == LOW)
led8State = HIGH;
else
led8State = LOW;
digitalWrite(led8Pin, led8State);
}
No comments:
Post a Comment