#1_09_05_intro to Arduino

  • Intro to Arduino code : Configuration, Variable, Function, changing parameters, Map
  • Light : LED, Super Bright White LED, RGB LED
  • Sensors : Photocell, Flex Sensor, Force Sensor

http://arduino.cc/en/Guide/MacOSX

AO_rgb

RGB LED CODE

———————————————————————————

Analog Input

AO

int x =0;

void setup(){
Serial.begin(9600);
pinMode(6, OUTPUT);
}

void loop(){
x = map(analogRead(A0),140,670,0,255);
analogWrite(6,x); //(pinNumber, Value);
Serial.println(x);
delay(10);
}

——————————————————

Multiple Photocell + RGB LED

001_bb

byte redPin = 3;
byte greenPin = 6;
byte bluePin = 5;
int x =0;
int y =0;
int z =0;

void setup() {
Serial.begin(9600);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

analogWrite(redPin,0); // everything starts black
analogWrite(greenPin,0);
analogWrite(bluePin,0);
}

void loop() {
Serial.println(x);
x = map(analogRead(A0), 550,900,0,255);
y = map(analogRead(A1), 550,900,0,255);
z = map(analogRead(A2), 550,900,0,255);
analogWrite(redPin,x); // makes magenta
analogWrite(greenPin,y);
analogWrite(bluePin,z);
}

Leave a comment