2013-04-14

ARDUINO

Seems I must be a geek. For my 40th birthday I got Arduino Uno kit with some extras like cool LCD display. It was already preloaded with a DEMO (old style) with greetings and wishes in scroll. :)

This my own (first ever) play with the device (apparently the RGB LED is too bright):



and source (it is newer than what the video shows):


/*
GDC TEST 20130414
*/

// Pin 13 has an LED connected on most Arduino boards.
const int led = 13;
const int led12 = 12;
const int led11 = 11;
const int led10 = 10;

const int greenLEDPin = 7;
const int redLEDPin = 6;
const int blueLEDPin = 5;

// the setup routine runs once when you press reset:
void setup() {               
  pinMode(led, OUTPUT);
  pinMode(led12, OUTPUT);
  pinMode(led11, OUTPUT);
  pinMode(led10, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
}

void Blink(int l, int d)
{
  digitalWrite(l, HIGH);
  delay(d);
  digitalWrite(l, LOW);
  delay(d);
}

void RGB(unsigned char r, unsigned char g, unsigned char b, int d)
{
  analogWrite(redLEDPin, r);
  analogWrite(greenLEDPin, g);
  analogWrite(blueLEDPin, b);
  delay(d);
}

// the loop routine runs over and over again forever:
void loop() {
  int i;
  for(i=1;i<8;i++) Blink(led, 150);
  RGB(255, 0, 0, 700);
  RGB(0, 255, 0, 700);
  RGB(0, 0, 255, 700);
  RGB(255, 255, 0, 700);
  RGB(255, 0, 255, 700);
  RGB(255, 64, 8, 700); 
  RGB(0, 200, 255, 700);
  RGB(255, 255, 255, 700);
  for(i=0;i<256;i++) RGB(i, 0, 0, 10);
  for(i=0;i<256;i++) RGB(255-i, 0, 0, 10);
  RGB(0, 0, 0, 0);
  for(i=0;i<6;i++)
  {
    Blink(led12, 500-i*100);
    Blink(led11, 500-i*100);
    Blink(led10, 500-i*100);
  }
}

No comments:

Post a Comment