Arduino


I started getting into microcontroller programming. I found a product called Arduino. I ended up buying it from a website called Adafruit Industries. The development environment is written in Java, but you write code in C and upload via USB to the ATmega168 microcontroller. I also purchased the LAN Module and am working on getting it to work with the following example. No such luck. So I decided to go to my friendly neighborhood Radio Shack and pick up some “supplies”. I found some multi-colored LED’s, a 7-segment LED Digital Display, a Potentiometer, and some other misc items. My first project was to create a counter that would count from 0 to 9 using the Potentiometer to control the delay. Below is a picture of the Arduino and my breadboard with the 7-segment LED wired up.

IMG_0348 

I have uploaded the code that I wrote to control the LED using the potentiometer.

int PinA = 7;
int PinB = 6;
int Dot = 5;
int PinC = 4;
int PinD = 0;
int PinE = 1;
int PinF = 3;
int PinG = 2;

int val = 0;
int potPin = 2;
int LEDState;

void setup()
{
for (int i=0;i<=8;i++) { pinMode(i, OUTPUT); } } void loop() { LEDState = digitalRead(Dot); if (LEDState == LOW) { digitalWrite(Dot, HIGH); }else{ digitalWrite(Dot, LOW); } val = analogRead(potPin); Number0(); delay(val); turn_all_off(); val = analogRead(potPin); Number1(); delay(val); turn_all_off(); val = analogRead(potPin); Number2(); delay(val); turn_all_off(); val = analogRead(potPin); Number3(); delay(val); turn_all_off(); val = analogRead(potPin); Number4(); delay(val); turn_all_off(); val = analogRead(potPin); Number5(); delay(val); turn_all_off(); val = analogRead(potPin); Number6(); delay(val); turn_all_off(); val = analogRead(potPin); Number7(); delay(val); turn_all_off(); val = analogRead(potPin); Number8(); delay(val); turn_all_off(); val = analogRead(potPin); Number9(); delay(val); turn_all_off(); } void turn_all_off() { for (int b=0;b<=8;b++) { if (b != 5) { digitalWrite(b, LOW); } } } void Number0() { digitalWrite(PinE, HIGH); digitalWrite(PinF, HIGH); digitalWrite(PinA, HIGH); digitalWrite(PinB, HIGH); digitalWrite(PinC, HIGH); digitalWrite(PinD, HIGH); } void Number1() { digitalWrite(PinB, HIGH); digitalWrite(PinC, HIGH); } void Number2() { digitalWrite(PinA, HIGH); digitalWrite(PinB, HIGH); digitalWrite(PinG, HIGH); digitalWrite(PinE, HIGH); digitalWrite(PinD, HIGH); } void Number3() { digitalWrite(PinA, HIGH); digitalWrite(PinB, HIGH); digitalWrite(PinG, HIGH); digitalWrite(PinC, HIGH); digitalWrite(PinD, HIGH); } void Number4() { digitalWrite(PinB, HIGH); digitalWrite(PinC, HIGH); digitalWrite(PinF, HIGH); digitalWrite(PinG, HIGH); } void Number5() { digitalWrite(PinA, HIGH); digitalWrite(PinF, HIGH); digitalWrite(PinG, HIGH); digitalWrite(PinC, HIGH); digitalWrite(PinD, HIGH); } void Number6() { digitalWrite(PinA, HIGH); digitalWrite(PinF, HIGH); digitalWrite(PinG, HIGH); digitalWrite(PinC, HIGH); digitalWrite(PinD, HIGH); digitalWrite(PinE, HIGH); } void Number7() { digitalWrite(PinA, HIGH); digitalWrite(PinB, HIGH); digitalWrite(PinC, HIGH); } void Number8() { digitalWrite(PinA, HIGH); digitalWrite(PinB, HIGH); digitalWrite(PinC, HIGH); digitalWrite(PinD, HIGH); digitalWrite(PinE, HIGH); digitalWrite(PinF, HIGH); digitalWrite(PinG, HIGH); } void Number9() { digitalWrite(PinA, HIGH); digitalWrite(PinB, HIGH); digitalWrite(PinC, HIGH); digitalWrite(PinD, HIGH); digitalWrite(PinF, HIGH); digitalWrite(PinG, HIGH); }


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.