I've just started using Arduino and I'm having trouble getting my code right.
Here is the task I need to do.
"Create a button read function
Hint: the function header should be int checkbutton ( void )
in the loop function, add code such that if the button has been pressed (i.e. the checkbutton function
returns 1), a message is sent to the serial monitor with your username."
There are no errors in the code but nothing happens in the serial monitor when I press the LED button and it does not return 0 when i don't press the LED button. Any sort of help would be appreciated!
Thanks!
int Button = 15; //LED and output are on the same pin
int last = 0;
void setup() {
Serial.begin(9600);
}
int button() {
pinMode(Button, INPUT);
int current = digitalRead(Button);
if (current and not last) {
delay(5);
pinMode(Button, OUTPUT);
Serial.print("Hey");
return 1;
}
else {
pinMode(Button, OUTPUT);
current == last;
return 0;
}
}
void loop() {
if (button >=0)
{
button();
}
else
{
;
}
}