I've been working on my grad project, for which I've decided to use an arduino. My goal is to make tic-tac-toe with LEDs. The way I have it set up is so each space in the game consists of 2 LEDs, one green and the other red. I'm using a potentiometer to select a pair and two buttons to select the color in each pair. I have what would be two rows currently wired, just to see if it all works. The circuit did function as planned before, but now none of the LEDs turn on at all when turning the potentiometer. I was hoping someone could see the problem that I can't seem to find. Here is a sample of the code for the first three pairs of LEDs:
const int analogPin = A0; //poteniometer, to choose pairs of leds
const int ledG1 = 13; //green led in first pair
const int ledR1 = 12; //red led in first pair
const int ledG2 = 11; //green led in second pair
const int ledR2 = 10; //red led in second pair
const int ledG3 = 9; //green led in third pair
const int ledR3 = 8; //red led in third pair
const int threshold1 = 112; //max analog value for first pair
const int threshold2 = 225; //max analog value for second pair
const int threshold3 = 338; //max analog value for third pair
const int buttonG = 51; //button to choose green led in pairs
const int buttonR = 53; //button to choose red led in pairs
int buttonGstate = 0;
int buttonRstate = 0;
int ledtoggle[6]; //if true (1), led should always be on. if false (0), led should be off
void setup() {
pinMode(ledG1, OUTPUT); //set leds as outputs
pinMode(ledR1, OUTPUT);
pinMode(ledG2, OUTPUT);
pinMode(ledR2, OUTPUT);
pinMode(ledG3, OUTPUT);
pinMode(ledR3, OUTPUT);
pinMode(ledG4, OUTPUT);
pinMode(ledR4, OUTPUT);
pinMode(ledG5, OUTPUT);
pinMode(ledR5, OUTPUT);
pinMode(ledG6, OUTPUT);
pinMode(buttonG, INPUT); //set buttons as inputs
pinMode(buttonR, INPUT);
Serial.begin(9600); //serial monitor
}
For the sake of length, I'll just put the part of loop that includes up to the first pair.
void loop() {
int i;
int analogValue = analogRead(analogPin);
buttonGstate = digitalRead(buttonG);
buttonRstate = digitalRead(buttonR);
for (i = 0; i < 6; i++) {
if (ledtoggle[i]) {
digitalWrite(ledtoggle[i], HIGH);
}
}
if (ledtoggle[0] == 0 && ledtoggle[1] == 0) {
if ((analogValue <= threshold1) && (analogValue > 0))
{
if (buttonGstate == HIGH && buttonRstate == LOW) {
digitalWrite(ledR1, LOW);
ledtoggle[0] = 1; }
else if(buttonGstate == LOW && buttonRstate == HIGH) {
digitalWrite(ledG1, LOW);
ledtoggle[1] = 1; }
else if(buttonRstate == LOW && buttonGstate == LOW) {
digitalWrite(ledG1, HIGH);
digitalWrite(ledR1, HIGH); }
else {
digitalWrite(ledG1, LOW);
digitalWrite(ledR1, LOW); }
}
}
Serial.println(analogValue);
}
Thanks again.