Arrrr .. duino :)
Published by stu on October 1st, 2007
in Electronics, Arduino
Hooray - my USB adaptor arrived this morning and within 1 hour of rigging up an Arduino compatible development board all sorts of cool things are happening! I decided to be a real cheapskate and build my Arduino myself rather than buy one. So it's all breadboarded and slightly rough looking, but on the plus side it works perfectly and I have another 9 AtMEGA8s sat around waiting for exciting things to happen to them.
Here's the obligatory YouTube video:
Showing the following:
- Reading an analogue value from a potentiometer
- Display that value on line 1 of LCD (in 4 bit nibble mode)
- Display the same value using a bar graph type output on line 2 of LCD
- Use the value to also set position of a servo.
All in Arduino's lovely C type syntax:
#include <lcd4bit.h>
#include <servo.h>
LCD4Bit lcd = LCD4Bit(2);
Servo servo1;
int potPin = 0;
int servoPin = 12;
int val = 0;
void setup() {
lcd.init();
servo1.setMaximumPulse(2200);
servo1.attach(servoPin);
}
void loop() {
val = analogRead(potPin);
char buf[12];
itoa(val, buf, 10);
// Print 1st line
lcd.cursorTo(1, 0);
lcd.printIn("Value: ");
lcd.printIn(buf);
lcd.printIn(" ");
// Print 2nd line
lcd.cursorTo(2, 0);
int steps = 255/16;
for (int i=0; i<16; i++) {
if ((val/4) > (steps*i)) {
lcd.print(0xFF);
} else {
lcd.printIn(" ");
}
}
// Keep positioning the servo while waiting to update the LCD
for (int x=0; x<50; x+=2) {
val = analogRead(potPin);
servo1.write(val/6);
Servo::refresh();
delay(2);
}
}
So easy! I am finished with trying to do PIC development on my Mac on a tight budget.
aabid on July 10th 2010
great post this this is i think
My blog - http://romantic18.blogspot.com
Stu (not verified) on January 21st 2008
Oliver H (not verified) on January 20th 2008
Stu (not verified) on January 20th 2008
Oliver H (not verified) on January 20th 2008
Post new comment