this is the Arduino code:
int potPin = 0; // Analog pin 0 connected to the potentiometer
int transistorPin = 9; // connected from digital pin 9 to the base of the transistor
int potValue = 0; // value returned from the potentiometer
void setup() { // set the transistor pin as an output
pinMode(transistorPin, OUTPUT);
Serial.begin(9600);
}
void loop() { // read the potentiometer, convert it to between 0 - 255 for the value accepted by the digital pin.
Serial.println(analogRead(A0));
potValue = analogRead(potPin) / 4; // potValue alters the supply from pin 9 which in turn controls the power running through the transistor
analogWrite(9, potValue);
potValue=Serial.read();
delay(50);
}
and this is the processing code:
import processing.serial.*;
Serial myPort;
float x;
color c;
String cadena;
float valorReal=0;
void setup(){
size(680,320);
smooth();
strokeWeight(2);
c=color(225,255,255);
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
myPort.clear();
}
void draw(){
background(255);
fill(c);
rect(0,280,150,-x);
fill(0,0,0);
line(150,280,150,0);
line(150,252,135,252);
line(150,224,120,224);
line(150,196,135,196);
line(150,168,120,168);
line(150,140,135,140);
line(150,112,120,112);
line(150,84,135,84);
line(150,56,120,56);
line(150,28,135,28);
textSize(32);
fill(0,0,0);
text("Velocidad",0, 310);
fill(0,0,0);
text("0%",150,280);
fill(0,0,0);
text("50%",150,140);
fill(0,0,0);
text("100%",150,30);
}
void serialEvent (Serial myPort) {
//Obtener cadena de puerto serial
cadena = myPort.readString();
if (cadena != null) {
//Quitar espacios en blanco
cadena = trim(cadena);
//Capturar cadena
valorReal = float(cadena);
}
x=map(valorReal,0,1023,0,280);
}
Some parts are in spanish xD
I'm sending the potenciometer output to the pin A0 of arduino, and sending the signal back from the pin 9.
On the pin A5 i'm sending the signal of the temperature sensor, but i don't know how to graph it.