Saturday, April 9, 2016

Graphing a sensor using Arduino


#Basic code
graphsize 900,300
font "arial",10,100
openserial 1, "COM4"
for window = 1 to 300
clg
for l = 25 to 325 step 25
line 30,l,900,l
text 0,l-5,5.5-int(l)/50+"V"
next l
for x = 1 to 900
pause .01
n=asc (read(1))
print n
circle x,277-2*n,2
next x
next window




// Arduino code
 int L = 0;
 int S = 0;         
void setup()
{  Serial.begin(9600); }

void loop()
{
  L = analogRead(2);
  S = map(L ,0,1023,0,127);
  //Serial.println(L); 
 Serial.write(S);       
  delay(50);
}

No comments:

Post a Comment