'blushing' LEDs
howdy! i'm making simple circuit 2 force sensors , 2 leds. need happen have leds both light when 1 or both of force sensors has pressure applied it.
here original code using 1 force sensor , 1 led:
the second led attached pin 5 , second force sensor attached analog pin 1. can post attempts @ adding second force sensor , led if need however, @ point, code more little muddled.
any suggestions welcome!
here original code using 1 force sensor , 1 led:
quote
/*
"one never dangerous when 1 has no shame, when 1 has grown old blush."
-marquis de sade (brainyquote.com)
*/
int ledvalue = 0; // led brightness
int ledpin1 = 9; // led connected digital pin 9
int sensorpin = 0; // force sensor connected analog pin 0
int sensorvalue = 0; // variable store value coming sensor
void setup()
{
pinmode(ledpin1, output); // sets ledpin1 output
serial.begin(9600); //initialize serial port
digitalwrite(ledpin1, high); // turn led on
}
void loop() // run on , on again
{
sensorvalue = analogread(sensorpin);
ledvalue = map(sensorvalue,0,1000,0,255); // set high , low outputs of sensor , led
analogwrite(ledpin1, ledvalue); // turn led on @ brightness set sensor
serial.println(sensorvalue); // send value computer
delay(100); // delay 1/10 of second
if (sensorvalue>300){ // if value coming computer greater 300
analogwrite(ledpin1, high); // turns on led
}
else {
(sensorvalue<300);
{ // if value coming computer less 300
analogwrite(ledpin1, low); // turns off leds
}
}
}
the second led attached pin 5 , second force sensor attached analog pin 1. can post attempts @ adding second force sensor , led if need however, @ point, code more little muddled.
any suggestions welcome!
the code add before setup() pretty straightforward. did have problems that?
the code add in setup() pretty straightforward. did have problems that?
in loop, need read both force sensors. that's easy.
actually, code turn way off, if led connected pwm pin, since high has value of 1. if led not connected pwm pin, code nothing.
what think code doing?
post code came with, , we'll working. you'll learn more if give answer.
the code add in setup() pretty straightforward. did have problems that?
in loop, need read both force sensors. that's easy.
code: [select]
analogwrite(ledpin1, high); // turns on ledactually, code turn way off, if led connected pwm pin, since high has value of 1. if led not connected pwm pin, code nothing.
code: [select]
(sensorvalue<300);what think code doing?
post code came with, , we'll working. you'll learn more if give answer.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > 'blushing' LEDs
arduino
Comments
Post a Comment