Monday, November 21, 2011

Button Control Assignment (CIRC-07): PART 3

PURPOSE:
The purpose is to make the counter only go up if both Button A and Button B are pressed!

EQUIPMENT:
  • 2 x Pushbuttons
  • 2 x 10k Ohm Resistor
  • 4 x 330 Ohm Resistor
  • 4 x LED
  • 10 x Wire (any colour)
  • 1 x Arduino Uno
  • 1 x Arduino Holder
  • 1 x Arduino Breadboard
  • 1 x Reference Sheet
PROGRAM DETAILS:  
In PART 3, only modifying Part 2 was done in a way so that the counter only goes up if both Button A and Button B are pressed! No building or changing the Arduino circuit was necessary.

TIME TO COMPLETE: 0 minutes to build the circuit, 10 minutes to code.

RESULTS:
Fortunately, there was no error and the program ran successfully!

PHOTOS OF PROJECT:
Assembled Button Control Circuit (PART 3)
TIPS:
Take your time writing out the code. Do not rush it or else your Arduino won’t do what you want it to do. Do not hesitate to ask your peers or Mr. Kee when you need help. Also, test and run your codes few times to see if it’s accurate.

FURTHER WORK:
PART 3 of this Button Control Assignment ends here so there is no need for any further work. However, I would like to research more about Pushbuttons and other Arduino parts to enhance my Arduino knowledge.

PROGRAM MODIFICATIONS:
My program looks similar to the one from. However, I used 4 LEDs and the corresponding number of 330 Ohm resistors to build my circuit for this assignment. Also, I followed the instructions from tiny.cc/ArduinoGuide (CIRC-07 Button Control Assignment PART 3). Thus, there are few changes in my program.

PROGRAM (codes): // Refer to Program codes in PART 2 for comments.

// CIRC-07 PART 3

int buttonA = 2;
int buttonB = 3;
int ledPin[] =  {13,12,11,10};    
int counter = 0;

void setup()
{
 for(int i = 0; i <4; i++)
{
    pinMode(ledPin[i], OUTPUT);
 } 
   pinMode(buttonA, INPUT);
   pinMode(buttonB, INPUT); 
}

void loop()
{
  int delayTime = 500;

  buttonA = digitalRead(2);
  buttonB = digitalRead(3);

while (!((buttonA==HIGH)&&(button==HIGH)))
{
   if (buttonA==HIGH)
{
   counter = counter + 1;
   digitalWrite(ledPin[0], HIGH); 
   delay(delayTime);
   digitalWrite(ledPin[0], LOW);
   delay(delayTime);
}
else if ((buttonB==HIGH)
{
if (counter >4)
   fourLED();
}

else if (counter == 0)
{
  delay(delayTime);
}
else
{
    counter--;
    digitalWrite(ledPin[counter],HIGH);
    delay(delayTime);
    digitalWrite(ledPin[counter],LOW);
    delay(delayTime);
 }
  }
}

void fourLED();
{
for(int i = 0; i <4; i++)
{
   digitalWrite(ledPin[counter],HIGH);
}
   delay(delayTime);

for(int i = 0; i <4; i++)
{
    digitalWrite(ledPin[counter],LOW);
}
   delay(delayTime);
}

REFERENCE:



No comments:

Post a Comment