Nesta One Day Digital Teachers: Arduino

Below is an image of the components we will be using for the following examples. The three black cylindrical fellow on the left are 10k potentiometers, the red chap next to them an LED to the right of that is an RGB LED with a common ground and the last little round black thing is a momentary push button. The wires are coloured as follows:

  • red [+5v]
  • blue [ground]
  • white [digital io]
  • yellow [analog in]
  • orange [pwm]
  • nesta_arduino_All

Example 1: blink

We need to hook up the LED to pin 13 with a jumper cable to make this work. The small surface mount led labeled L on the arduino will also flash when this sketch is uploaded.

int led = 13;
void setup(){
  pinMode(led,OUTPUT);
}

void loop(){
  digitalWrite(led,HIGH);
  delay(500);
  digitalWrite(led,LOW);
  delay(500);
}

Example 1: blink time vary

void loop(){
  int timeDelay = analogRead(0);

  digitalWrite(led,HIGH);
  delay(timeDelay);
  digitalWrite(led,LOW);
  delay(timeDelay);
}

Example 1: blink button

int led = 13;
int button = 2;

void setup(){
  pinMode(led,OUTPUT);
  pinMode(button,INPUT);
}

void loop(){
  if(digitalRead(button) == HIGH){
    digitalWrite(led,HIGH);
    delay(500);
    digitalWrite(led,LOW);
    delay(500);
  }
}

Example 1: Light colour function

int red = 9;
int green = 11;
int blue = 10;

void setup(){
  pinMode(red,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(blue,OUTPUT);
}

void loop(){
  rgb_led(random(255),random(255),random(255));
  delay(100);
}

void rgb_led(int r,int g, int b){
  analogWrite(red,r);
  analogWrite(green,g);
  analogWrite(blue,b);
}

Example 1: Light and Sound

int red = 9;
int green = 11;
int blue = 10;

void setup(){
  pinMode(red,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(blue,OUTPUT);
}
void loop(){
  rgb_led(random(255),random(255),random(255));
  tone(8,random(200,1000));
  delay(20);
  noTone(8);
  delay(20);
}
void rgb_led(int r,int g, int b){
  analogWrite(red,r);
  analogWrite(green,g);
  analogWrite(blue,b);
}
Advertisements

One Response to Nesta One Day Digital Teachers: Arduino

  1. Pingback: One Day Digital: teachers | Short and Dishevelled

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s