David Anasco
/
FTHR_HelloWorld
blinks various LED when pushing a button. no external components needed.
main.cpp@1:2b22aebf8622, 2021-07-14 (annotated)
- Committer:
- davidanasco
- Date:
- Wed Jul 14 07:18:30 2021 +0000
- Revision:
- 1:2b22aebf8622
- Parent:
- 0:c2dd4b719b00
debug'd and commented
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davidanasco | 0:c2dd4b719b00 | 1 | #include "mbed.h" |
davidanasco | 0:c2dd4b719b00 | 2 | #include "max32630fthr.h" |
davidanasco | 0:c2dd4b719b00 | 3 | |
davidanasco | 1:2b22aebf8622 | 4 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); // set signal levels to 3v3 |
davidanasco | 0:c2dd4b719b00 | 5 | |
davidanasco | 1:2b22aebf8622 | 6 | DigitalOut redLED(LED1); // declare outputs |
davidanasco | 0:c2dd4b719b00 | 7 | DigitalOut greenLED(LED2); |
davidanasco | 0:c2dd4b719b00 | 8 | DigitalOut blueLED(LED3); |
davidanasco | 1:2b22aebf8622 | 9 | |
davidanasco | 1:2b22aebf8622 | 10 | DigitalIn pushButton(P2_3, PullUp); // declare input. and set it to hi by default. |
davidanasco | 0:c2dd4b719b00 | 11 | |
davidanasco | 0:c2dd4b719b00 | 12 | int main(){ |
davidanasco | 1:2b22aebf8622 | 13 | printf("So it has begun...\r\n"); // send message thru serial (view with laptop terminal) |
davidanasco | 1:2b22aebf8622 | 14 | wait(1); // wait 1 second |
davidanasco | 0:c2dd4b719b00 | 15 | |
davidanasco | 0:c2dd4b719b00 | 16 | redLED = LED_OFF; |
davidanasco | 0:c2dd4b719b00 | 17 | greenLED = LED_OFF; |
davidanasco | 0:c2dd4b719b00 | 18 | blueLED = LED_OFF; |
davidanasco | 0:c2dd4b719b00 | 19 | int roundabout = 0; |
davidanasco | 0:c2dd4b719b00 | 20 | while(1){ |
davidanasco | 0:c2dd4b719b00 | 21 | |
davidanasco | 0:c2dd4b719b00 | 22 | if(pushButton==0){ |
davidanasco | 1:2b22aebf8622 | 23 | roundabout++; // every push, increment color selector by 1 |
davidanasco | 0:c2dd4b719b00 | 24 | |
davidanasco | 1:2b22aebf8622 | 25 | // reset to dark before changing color |
davidanasco | 0:c2dd4b719b00 | 26 | redLED = LED_OFF; |
davidanasco | 0:c2dd4b719b00 | 27 | greenLED = LED_OFF; |
davidanasco | 0:c2dd4b719b00 | 28 | blueLED = LED_OFF; |
davidanasco | 1:2b22aebf8622 | 29 | |
davidanasco | 1:2b22aebf8622 | 30 | switch(roundabout){ // asks what will the new color be |
davidanasco | 0:c2dd4b719b00 | 31 | case 1: |
davidanasco | 1:2b22aebf8622 | 32 | redLED = LED_ON; // red only |
davidanasco | 0:c2dd4b719b00 | 33 | break; |
davidanasco | 0:c2dd4b719b00 | 34 | case 2: |
davidanasco | 1:2b22aebf8622 | 35 | greenLED = LED_ON; // green only |
davidanasco | 0:c2dd4b719b00 | 36 | break; |
davidanasco | 0:c2dd4b719b00 | 37 | case 3: |
davidanasco | 1:2b22aebf8622 | 38 | blueLED = LED_ON; // blue only |
davidanasco | 0:c2dd4b719b00 | 39 | break; |
davidanasco | 0:c2dd4b719b00 | 40 | case 4: |
davidanasco | 1:2b22aebf8622 | 41 | redLED = LED_ON; // yellow |
davidanasco | 0:c2dd4b719b00 | 42 | greenLED = LED_ON; |
davidanasco | 0:c2dd4b719b00 | 43 | break; |
davidanasco | 0:c2dd4b719b00 | 44 | case 5: |
davidanasco | 1:2b22aebf8622 | 45 | greenLED = LED_ON; // aqua |
davidanasco | 0:c2dd4b719b00 | 46 | blueLED = LED_ON; |
davidanasco | 1:2b22aebf8622 | 47 | break; |
davidanasco | 0:c2dd4b719b00 | 48 | case 6: |
davidanasco | 1:2b22aebf8622 | 49 | blueLED = LED_ON; // purple |
davidanasco | 0:c2dd4b719b00 | 50 | redLED = LED_ON; |
davidanasco | 0:c2dd4b719b00 | 51 | break; |
davidanasco | 0:c2dd4b719b00 | 52 | case 7: |
davidanasco | 1:2b22aebf8622 | 53 | redLED = LED_ON; // white |
davidanasco | 0:c2dd4b719b00 | 54 | greenLED = LED_ON; |
davidanasco | 0:c2dd4b719b00 | 55 | blueLED = LED_ON; |
davidanasco | 0:c2dd4b719b00 | 56 | break; |
davidanasco | 1:2b22aebf8622 | 57 | default: |
davidanasco | 1:2b22aebf8622 | 58 | roundabout = 0; // reset back to dark |
davidanasco | 1:2b22aebf8622 | 59 | break; |
davidanasco | 0:c2dd4b719b00 | 60 | } |
davidanasco | 1:2b22aebf8622 | 61 | wait(1); // wait 1 second before taking input signal again. without this, colors would switch very fast |
davidanasco | 0:c2dd4b719b00 | 62 | } |
davidanasco | 0:c2dd4b719b00 | 63 | } |
davidanasco | 0:c2dd4b719b00 | 64 | } |