Sunday, June 3, 2012

Arduino the Aardvark

I've been playing around with Arduino with a friend recently. It's similar to that basic stamp/ microcontroller stuff we played around with in Tech class in high school. I was really horrible at it and never thought I'd be interested in it.. ever again! SO glad to be done with it! But then recently, I signed up for this course called Making Things Interactive because I was craving some technical skills. Oh the irony. Throughout high school, I was looking for a creative outlet and now in college, I am looking for technical ones! 


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;  } 
}


2 comments:

  1. XD so far ahead already! Make it taste the sweetness of your oatmeal next time. program a bib? spoon?

    ReplyDelete
    Replies
    1. Thanks for the suggestion! Hopefully I'll get good enough to know how to do that! :)

      Delete