Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 1 month ago.
Blinking LED with 2 inputs
Hello, I am new to microcontroller and c++ coding :) I am trying to write a code that does the following: 1. For every digital input pulse, the LED keeps switching ON/OFF (blinking loop). 2. Another input button which switch the LED ON or Off (here is no looping).
For this I made a state diagrams and some code for mbed LPC-1768 micorcontroller but can't check online as it doesn't have simlator. I would appreciate a lot if you would check this out :)

#include "mbed.h"
DigitalOut myled(LED1);
DigitalIn input(p17);
// p17 is pin17 where the pulse generator is connected //
int states;
bool button;
int main(){
while (button ==1){
switch(states){
case 0:
input == 1;
myled = 1;
break;
case 1:
input == 0;
myled = 0;
break;
}
}
}
Information
I have not added much about when the button is OFF as the while loop breaks (button ==0) and program terminates with LED off (not sure leaving that is ok tho). I would love any criticism or advice on my coding thought process and implementation of idea->code. (for eg im not sure about my usage of switch command...any other stuffs like if-else might have been better i think.
Assigned to 9 years, 1 month ago.
This means that the question has been accepted and is being worked on.