Thursday, 19 January 2012

Playing with light sensors

So if I want to make a visual display of the what the arduino light sensor is picking up, I have to use software called Processing

In Arduino:
File/Examples/Firmata/Standard Firmata
(This needs to have been downoaded from Arduino Reference and stored in the Arduino library)
(Library location can be found via Arduino/Preferences in the arduino software)
Upload to arduino device and close program

In Processing:
Open the example arduino file
(This needs to be downloaded from the Processing Reference page and saved into the Processing library)
(Library location can be found via Processing/Preferences in the arduino software)



import processing.serial.* ;

import cc.arduino.*;

Arduino arduino;

color off = color(4, 79, 111);
color on = color(84, 145, 158); (<-- this says what colour will show when the light sensor is fully on and fully; and fade between the two. Colours are done in RGB)

void setup() {
  size(470, 280); (<-- display screen size)
  arduino = new Arduino(this, Arduino.list()[0], 57600);

}

void draw() {
 println(arduino.analogRead(0)); (<-- Make sure this says "analogRead", and not just "read")
}

This makes the light sensor readings show at the bottom

In order to show something more visual, I need to add some more functions into "void draw":

void draw(){
println (arduino.analogRead(0));

 background (255,103,255); 
 int input = arduino.analogRead(0);
 ellipse (500,500,input,input); (<-- circle (position x, position y, size x, size y)
 fill (input/4, input/8, input/12);  (<-- input affects colour in RGB)
}



No comments:

Post a Comment