Here's one of the things my friend and I made:
When the button on the left is pressed, the LEDs light up one by one from the left side. When the button on the right is pressed, the LEDs light up starting from the right.
This is the code we wrote for it if anyone is interested:
//Set constants for the pins used
const int lowestPin = 2;
const int highestPin = 7;
const int buttonone = 8;
const int buttontwo = 9;
//currentState of the button; when it equals 2, no buttons are pushed
int currentState = 2;
void setup() {
// set pins 2 through 13 as outputs:
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++)
{ pinMode(thisPin, OUTPUT); }
//set pins 8 and 9 as inputs:
pinMode(buttonone, INPUT);
pinMode(buttontwo, INPUT); }
void loop() {
//Read the state of the buttons
int buttononeState = digitalRead(buttonone);
int buttontwoState = digitalRead(buttontwo);
//Change the currentState according to which button is pressed
if(buttononeState == HIGH) {
currentState = 1; }
if (buttontwoState == HIGH) {
currentState = 0; }
else currentState = currentState;
//lighting sequence if button one is pushed
if(currentState == 1) {
for (int thisPin = lowestPin; thisPin <=highestPin; thisPin++)
{ analogWrite(thisPin, 255);
delay(200);
analogWrite(thisPin,0); }
currentState=2; }
//lighting sequence if button two is pushed
if(currentState == 0) {
for (int thisPin = highestPin; thisPin >=lowestPin; thisPin--)
{ analogWrite(thisPin, 255);
delay(200);
analogWrite(thisPin,0); }
currentState=2; }
}
XD so far ahead already! Make it taste the sweetness of your oatmeal next time. program a bib? spoon?
ReplyDeleteThanks for the suggestion! Hopefully I'll get good enough to know how to do that! :)
Delete