Thursday, December 1, 2011

Arduino



Not the most impressive program I have ever written, but considering the Arduino only arrived this morning it's not a bad start (I also have an 8x8 LED array which I will be playing around with later). Setting up the Arduino development environment on Linux was simple: downloaded and unzipped the IDE, installed the gcc-avr and avr-libc packages, and added myself to the dialout group (sudo usermod -aG dialout nja) as described on this page. [Edit: on my home netbook, running Ubuntu 11.10 rather than Linux Mint, I had to edit /hardware/arduino/cores/arduino/wiring.h and comment out the line starting #define round (line 79), as described here]

const int RED_LED = 9;
const int AMBER_LED = 10;
const int GREEN_LED = 11;
const int ON = 0xFF;
const int OFF = 0x00;

void setup()
{
  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(AMBER_LED, OUTPUT);
}

void loop()
{
  analogWrite(AMBER_LED, OFF);
  analogWrite(RED_LED, ON);
  delay(1000);
  analogWrite(AMBER_LED, ON);
  delay(1000);
  analogWrite(RED_LED, OFF);
  analogWrite(AMBER_LED, OFF);
  analogWrite(GREEN_LED, ON);
  delay(1000);
  analogWrite(AMBER_LED, ON);
  analogWrite(GREEN_LED, OFF);
  delay(1000);  
}

No comments:

Post a Comment