I was able to control the fading of all three LEDs as well as get them all to blink in unison using 2 pots. I then replaced one of the pots with the FSR and got the same result. I was then able to have the input from the FSR and the pot influence the rate of the painted balls in the Example code.
Components:
Arduino microprocessor
Breadboard
Force Sensitive Receptor
1 potentiometer
Arduino programming environment
Processing environment
3 LEDs
Arduino Code
*/
int potPin1 = 0; // select the input pin for the first potentiometer
int potPin2 = 1; //select the input pin for the second potentiometer
int ledPin1 = 9; // select the pin for the LED1
int ledPin2 = 10; //select the pin for LED2
int ledPin3 = 11; //select the pin for LED3
int pot1Val = 0; //variable to store the value coming from pot 1
int pot2Val = 0; //variable to store the value coming from pot 2
void setup() {
Serial.begin(9600);
pinMode(ledPin1, OUTPUT); // declare the ledPin1 as an OUTPUT
pinMode(ledPin2, OUTPUT); // declare the ledPin2 as an OUTPUT
pinMode(ledPin3, OUTPUT); // declare the ledPin3 as an OUTPUT
}
void loop() {
pot1Val = analogRead(potPin1); // read the value from the sensor, between 0 - 1024
pot2Val = analogRead(potPin2); //read the value from the sensor, between 0 - 1024
Serial.println(pot1Val);
Serial.println(pot2Val);
analogWrite(ledPin1, pot1Val/4); // analogWrite can be between 0-255
analogWrite(ledPin2, pot1Val/4);
analogWrite(ledPin3, pot1Val/4);
delay(pot2Val); //stop program for some time, LEDs are on for this time period.
analogWrite(ledPin1, 0); //dim LED to completely dark
analogWrite(ledPin2, 0); //dim LED to completely dark
analogWrite(ledPin3, 0); //dim LED to completely dark
delay(pot2Val); //Stop program for some time, LEDs are off for this time period.
}
Processing Code:
/*
* Arduino Ball Paint
* (Arduino Ball, modified)
* ----------------------
*
* Draw balls randomly on the screen, size controlled by a device
* on a serial port. Press space bar to clear screen, or any
* other key to generate fixed-size random balls.
*
* Receives an ASCII number over the serial port,
* terminated with a carriage return (ascii 13) then newline (10).
*
* This matches what Arduino's " Serial.println(val)" function
* puts out.
*
* Created 25 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbserial-A4001nQ5"; // or "COM5"
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
void setup() {
size(300,300);
frameRate(10);
smooth();
background(80,80,80);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
if(key == ' ') {
background(40,40,40); // erase screen
}
else {
int x = int(random(0,width));
int y = int(random(0,height));
drawball(x,y, 50);
}
}
// draw balls
void drawball(int x, int y, int r) {
for (int i=0; i<100; i++ ) {
fill(255-i,i,240);
ellipse(x,y,r,r);
}
}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
println("val="+val);
int x = int(random(0,width));
int y = int(random(0,height));
drawball(x,y,val);
buf = "";
background(40,40,40); // erase screen
}
}
Comments
your photos didn't show :(
your photos didn't show :(