Hi,
i have rewritten the code a little bit:
int whiteledPin = 9; // pin 9 has the white led connected
int blueledPin = 10; // pin 10 has the blue led connected
int hallPin = 11; // pin 11 has the hall sensor connected
void setup() {
// initialize the pins as output/input and set output to 0
pinMode(whiteledPin, OUTPUT);
pinMode(blueledPin, OUTPUT);
pinMode(hallPin, INPUT);
analogWrite(whiteledPin,0)
digitalWrite(blueledPin, LOW);
}
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void loop()
{
reading = digitalRead(hallPin);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
{
analogWrite(whiteledPin,64);
}
if (whiteledPin == 64 && blueledPin == 0)
{
analogWrite(ledPinwhite,128);
}
if (whiteledPin == 128 && blueledPin == 0)
{
analogWrite(ledPinwhite,254);
}
if (whiteledPin == 254 && blueledPin == 0)
{
analogWrite(whiteledPin,0);
analogWrite(blueledPin,255);
}
if (whiteledPin == 0 && blueledPin == 255)
{
analogWrite(blueledPin,0);
}
time = millis();
}
previous = reading;
}
but now i see a other problem. when the button is pressed the output will be set to:
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
{
analogWrite(whiteledPin,64);
but the next press will also set it only to:
analogWrite(whiteledPin,64)
right?
other question. is it possible to read out the pwm state of an anlog output like this?
if (whiteledPin == 64 && blueledPin == 0)