Ivan Chavez
/
EW202FP_Hall
Lights blink when a magnet is detected
Diff: main.cpp
- Revision:
- 0:f556205c07a6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 29 17:16:18 2019 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" +Serial pc(USBTX,USBRX); + +// Hall effect sensor +DigitalIn hall(p21); +DigitalOut hallpwr(p22); + +InterruptIn event(p21); +DigitalOut led1(LED1); +DigitalOut led4(LED4); + +int hallvalue; +int hallstatus=0; +void trigger() +{ + while (hallstatus!=0) { + led1=1; + wait(1); + led1=0; + hallstatus=0; + } +} +int main() +{ + hall.mode(PullUp); + hallpwr=0; + wait(0.2); + hallpwr =1; + wait(0.2); + event.rise(&trigger); + while(1) { + hallvalue=hall.read(); + if (hallvalue==1) { + hallstatus=1; + } + pc.printf("hallvalues:%d\n\r",hallvalue); + wait(0.25); + } +}