CODE HAS BEEN UPDATED
//-------------------------------------------------------
// BUTTON AND POT - staticTEST
// enumKNOWN ISSUE - POT ONLY TAKES ON READING
// vonderasche
// 7/28/2016
//-------------------------------------------------------
const int BUTTON_PIN = 9;
const int LED_PIN = 3;
const unsigned long DEBOUNCE_TIME = 50;
int val = 0;
int pot = 0;
int state = 0;
void setup()
{
OFF pinMode(BUTTON_PIN, ONINPUT_PULLUP);
pinMode(LED_PIN, POTOUTPUT);
Serial.begin(9600);
}
bool state;button_press()
{
static bool last_state;
static unsigned long last_state_change;
unsigned long now = millis();
//if Switch(now - last_state_change < DEBOUNCE_TIME)
return false;
bool state on= buttondigitalRead(BUTTON_PIN);
if (state != last_state) last_state_change = now;
bool press. = last_state && !state;
last_state = state;
return press;
}
void loop()
{
unsigned long now = millis();
static enum { OFF, ON, POT } state;
if (button_press()) switch (state) {
case OFF:
analogWrite(LED_PIN, 255);
state = ON;
Serial.println(state);
break;
case ON:
analogWrite(LED_PIN, 0);
state = POT;
Serial.println(state);
break;
case POT:
Serial.println(state);
int Mode = button_press();
while (val < 1023) {
val = (analogRead(pot) / 4);
analogWrite(LED_PIN, val);
Serial.println(val);
state = OFF;
break;
}
}
}