What i'm trying to achieve is to have one led blink faster when I push down and another LED blink faster when I push to the left.
It is not working and I don't know why. When I move my joy stick in one direction both lights change the frequency of their blinks. Other times they don't change at all. I'm completely lost. Could somebody please tell me if it's my program or my wiring.
I wired both L/R's to A2 and both U/D's to A5
Here is my program….
const int ledPin = 13;
const int ledPin2 = 12; // the number of the LED pin
// Variables will change:
int ledState = LOW;
int ledState2 = LOW; // ledState used to set the LED
long previousMillis = 0;
long previousMillis2 = 0;// will store last time LED was updated
int time = 2;
int time2 = 5;
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
long interval2 = 100;
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
long interval = analogRead(time);
long interval2 = analogRead(time2);
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
//////////////////////////////////////////////////
unsigned long currentMillis = millis();
if(currentMillis - previousMillis2 > interval2) {
// save the last time you blinked the LED
previousMillis2 = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState2 == LOW)
ledState2 = HIGH;
else
ledState2 = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin2, ledState2);
}
}
}
Thanks,
Drew Davis