Exercise 7

Arduino Code:

int potPin = 2; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(9600);
}

void loop() {
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time

Serial.print(val);
}
Processing Code:

import processing.serial.*;

Serial port;

int Length = 200;
int Width = 300;

void setup()
{
println(Serial.list());
size (Width, Length);
background(0,0,0);
port = new Serial(this, Serial.list()[1], 9600);
// frameRate(10);
}

int value =255;

void draw() {
fill(255);
rect(50, 50, 200, 100);

int val = port.read();
println(" " + val + " ");
fill(val);
rect(50, 50, 200, 100);

}

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License