nothing is happening on the serial monitor. The led pin has nothing plugged in as this is the part of a larger project im testing it before adding it below i the code and a describtion of the prototyping board i have set up. PLEASE HELP
int rtime = 1;
int newrtime = 1;
int up;
int down;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
up = digitalRead(2);
down = digitalRead(3);
if(rtime != newrtime)
{
if(up == HIGH)
{
rtime++;
Serial.println("up");
Serial.println(rtime);
}
else if(down == HIGH)
{
rtime--;
Serial.println(rtime);
Serial.println("off");
}
Serial.println(rtime);
}
newrtime = rtime;
eventually this will be used to change the timing lights are on and off one push button for up one for down. this is just a test to make sure its reading the buttons and its not reading either currently
Please read the post at the start of any forum , entitled "How to use this Forum".
OR http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
//Version 1.00
#define isPUSHED LOW
byte up;
byte down;
byte lastUpSwitchState;
byte lastDownSwitchState;
int rtime = 1;
int newrtime = 1;
const byte upSwitch = 2;
const byte downSwitch = 3;
const byte myLED = 4;
const byte heartBeatLED = 13;
unsigned long currentMillis;
unsigned long heartBeatMillis;
unsigned long switchMillis;
unsigned long myLEDmillis;
//*****************************************************************************
void setup()
{
Serial.begin(9600);
pinMode(heartBeatLED, OUTPUT);
pinMode(myLED, OUTPUT);
pinMode(upSwitch, INPUT_PULLUP);
pinMode(downSwitch, INPUT_PULLUP);
pinMode(4, OUTPUT);
} //END of setup()
//*****************************************************************************
void loop()
{
//leave this line of code at the top of loop()
currentMillis = millis();
//*******************************
//toggle the heartbeat LED every 1/2 second
if (currentMillis - heartBeatMillis >= 500)
{
//start the TIMER
heartBeatMillis = currentMillis;
//toggle LED
digitalWrite(heartBeatLED, !digitalRead(heartBeatLED));
}
//*******************************
//check the switch(es) every 50ms
if (currentMillis - switchMillis >= 50)
{
//start the TIMER
switchMillis = currentMillis;
checkSwitch();
}
//*******************************
//Time to toggle the LED ?
if (currentMillis - myLEDmillis >= rtime * 1000ul)
{
//start the TIMER
myLEDmillis = currentMillis;
//toggle the myLED
digitalWrite(myLED, !digitalRead(myLED));
Serial.println("hi");
}
} //END of loop()
// c h e c k S w i t c h ( )
//*****************************************************************************
void checkSwitch()
{
byte currentState;
//*******************************
//upSwitch
currentState = digitalRead(upSwitch);
if (lastUpSwitchState != currentState)
{
//update to the current state
lastUpSwitchState = currentState;
//we have just gone to the isPUSHED state?
if (currentState == isPUSHED)
{
rtime++;
if (rtime >= 10)
{
//don't go over 10
rtime = 10;
}
//restart the TIMER
myLEDmillis = currentMillis;
Serial.println("up");
Serial.println(rtime);
}
}
//*******************************
//downSwitch
currentState = digitalRead(downSwitch);
if (lastDownSwitchState != currentState)
{
//update to the current state
lastDownSwitchState = currentState;
//we have just gone to the isPUSHED state?
if (currentState == isPUSHED)
{
rtime--;
if (rtime < 1)
{
//don't go under 1
rtime = 1;
}
//restart the TIMER
myLEDmillis = currentMillis;
Serial.println("down");
Serial.println(rtime);
}
}
//*******************************
} //END of checkSwitch()
//*****************************************************************************
as for your original code, maybe this is what you wanted?
int rtime = 0;
int up;
int down;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
up = digitalRead(2);
down = digitalRead(3);
if(up == LOW){
rtime++; //rtime = rtime+100; for 100 ms increments
Serial.println("up");
Serial.println(rtime);
}
if(down == LOW){
rtime--;
Serial.println(rtime);
Serial.println("down");
}
digitalWrite(4, HIGH);
delay(rtime);
Serial.println("hi");
}