![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
driving software for a simple electromagnet circuit. For a uni project.
main.cpp@0:64f1952778a3, 2015-09-25 (annotated)
- Committer:
- teunman
- Date:
- Fri Sep 25 14:37:44 2015 +0000
- Revision:
- 0:64f1952778a3
Electromagnet working if the button SW3 is pressed. It also shows the LED2 is on if the button is pushed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
teunman | 0:64f1952778a3 | 1 | #include "mbed.h" |
teunman | 0:64f1952778a3 | 2 | |
teunman | 0:64f1952778a3 | 3 | DigitalOut magnet(D4); //magnet is defined on D4 |
teunman | 0:64f1952778a3 | 4 | DigitalOut led(LED2); //LED is defined as LED2 |
teunman | 0:64f1952778a3 | 5 | DigitalIn knop(SW3); //knop is defined on SW3 |
teunman | 0:64f1952778a3 | 6 | |
teunman | 0:64f1952778a3 | 7 | |
teunman | 0:64f1952778a3 | 8 | int main() { |
teunman | 0:64f1952778a3 | 9 | |
teunman | 0:64f1952778a3 | 10 | led = 1; //defines LED is off |
teunman | 0:64f1952778a3 | 11 | |
teunman | 0:64f1952778a3 | 12 | |
teunman | 0:64f1952778a3 | 13 | while(true){ |
teunman | 0:64f1952778a3 | 14 | |
teunman | 0:64f1952778a3 | 15 | if (knop == 0){ //if button is pressed |
teunman | 0:64f1952778a3 | 16 | led = 0; // defines LED is on when button is pressed |
teunman | 0:64f1952778a3 | 17 | magnet = 1; //magnet is on |
teunman | 0:64f1952778a3 | 18 | } |
teunman | 0:64f1952778a3 | 19 | else{ |
teunman | 0:64f1952778a3 | 20 | led = 1; // LED is off |
teunman | 0:64f1952778a3 | 21 | magnet = 0; //magnet is off |
teunman | 0:64f1952778a3 | 22 | } |
teunman | 0:64f1952778a3 | 23 | } |
teunman | 0:64f1952778a3 | 24 | |
teunman | 0:64f1952778a3 | 25 | |
teunman | 0:64f1952778a3 | 26 | |
teunman | 0:64f1952778a3 | 27 | } |