Report
2 years, 8 months 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 :)

/media/uploads/bijay007/state_diagram_led.jpg

#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.

Comment on this question
Be the first to answer this question.

Assigned to Bijay Timilsina 2 years, 8 months ago.

This means that the question has been accepted and is being worked on.

To post an answer, please log in.