![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A blinky variation for the mBuino with a bunch of different blink modes, deep-sleeping between iterations.
Dependencies: Crypto RNG mbed WakeUp
Fork of mBuinoBlinky by
mBuino blinky experiments.
main.cpp@10:8a901b6d8cfa, 2014-09-08 (annotated)
- Committer:
- mikewebkist
- Date:
- Mon Sep 08 01:20:52 2014 +0000
- Revision:
- 10:8a901b6d8cfa
- Parent:
- 9:7ae675372031
- Child:
- 11:be76674d2dbd
Deep Sleep after one iteration: http://mbed.org/forum/repo-52552-mBuino_low_power_led_flasher-community/topic/5130/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Experiment626 | 0:aa0e1ad88af5 | 1 | #include "mbed.h" |
mikewebkist | 2:fd6008aa85cd | 2 | #include "RNG/Random.h" |
Experiment626 | 0:aa0e1ad88af5 | 3 | |
Experiment626 | 0:aa0e1ad88af5 | 4 | DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs |
Experiment626 | 0:aa0e1ad88af5 | 5 | |
mikewebkist | 2:fd6008aa85cd | 6 | int rndLED = 0; |
mikewebkist | 2:fd6008aa85cd | 7 | Random RNG = Random(); |
Experiment626 | 0:aa0e1ad88af5 | 8 | |
mikewebkist | 10:8a901b6d8cfa | 9 | void myDeepSleep() { |
mikewebkist | 10:8a901b6d8cfa | 10 | LPC_PMU->PCON = 0x1; |
mikewebkist | 10:8a901b6d8cfa | 11 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mikewebkist | 10:8a901b6d8cfa | 12 | LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800; |
mikewebkist | 10:8a901b6d8cfa | 13 | __WFI(); |
mikewebkist | 10:8a901b6d8cfa | 14 | } |
mikewebkist | 10:8a901b6d8cfa | 15 | |
mikewebkist | 4:eea1a71b9a11 | 16 | void sweep(float delayTime) |
Experiment626 | 0:aa0e1ad88af5 | 17 | { |
mikewebkist | 1:47c61bf9c81e | 18 | for(int x=0; x<7; x++) |
Experiment626 | 0:aa0e1ad88af5 | 19 | { |
mikewebkist | 1:47c61bf9c81e | 20 | LED[x] = 1; |
mikewebkist | 1:47c61bf9c81e | 21 | wait(delayTime); |
Experiment626 | 0:aa0e1ad88af5 | 22 | } |
mikewebkist | 2:fd6008aa85cd | 23 | |
mikewebkist | 2:fd6008aa85cd | 24 | for(int x=6; x>=0; x--) |
Experiment626 | 0:aa0e1ad88af5 | 25 | { |
mikewebkist | 2:fd6008aa85cd | 26 | LED[x] = 0; |
mikewebkist | 1:47c61bf9c81e | 27 | wait(delayTime); |
Experiment626 | 0:aa0e1ad88af5 | 28 | } |
mikewebkist | 4:eea1a71b9a11 | 29 | } |
mikewebkist | 4:eea1a71b9a11 | 30 | |
mikewebkist | 6:fe79549495e0 | 31 | void bounceMode(float delayTime) |
mikewebkist | 6:fe79549495e0 | 32 | { |
mikewebkist | 6:fe79549495e0 | 33 | for(int x=0; x<7; x++) |
mikewebkist | 6:fe79549495e0 | 34 | { |
mikewebkist | 6:fe79549495e0 | 35 | LED[x] = 1; |
mikewebkist | 6:fe79549495e0 | 36 | wait(delayTime); |
mikewebkist | 6:fe79549495e0 | 37 | LED[x] = 0; |
mikewebkist | 6:fe79549495e0 | 38 | } |
mikewebkist | 6:fe79549495e0 | 39 | |
mikewebkist | 6:fe79549495e0 | 40 | for(int x=6; x>=0; x--) |
mikewebkist | 6:fe79549495e0 | 41 | { |
mikewebkist | 6:fe79549495e0 | 42 | LED[x] = 1; |
mikewebkist | 6:fe79549495e0 | 43 | wait(delayTime); |
mikewebkist | 6:fe79549495e0 | 44 | LED[x] = 0; |
mikewebkist | 6:fe79549495e0 | 45 | } |
mikewebkist | 6:fe79549495e0 | 46 | } |
mikewebkist | 6:fe79549495e0 | 47 | |
mikewebkist | 9:7ae675372031 | 48 | void multiSweepMode(float delayTime) |
mikewebkist | 9:7ae675372031 | 49 | { |
mikewebkist | 9:7ae675372031 | 50 | for(int w=1; w<13; w++) |
mikewebkist | 9:7ae675372031 | 51 | { |
mikewebkist | 9:7ae675372031 | 52 | for(int x=1-w; x<13; x++) |
mikewebkist | 9:7ae675372031 | 53 | { |
mikewebkist | 9:7ae675372031 | 54 | for(int z=0; z<w; z++) { |
mikewebkist | 9:7ae675372031 | 55 | if(x+z>=0 && x+z < 7) { |
mikewebkist | 9:7ae675372031 | 56 | LED[x+z]=1; |
mikewebkist | 9:7ae675372031 | 57 | } |
mikewebkist | 9:7ae675372031 | 58 | } |
mikewebkist | 9:7ae675372031 | 59 | wait(delayTime); |
mikewebkist | 9:7ae675372031 | 60 | for(int z=0; z<w; z++) { |
mikewebkist | 9:7ae675372031 | 61 | if(x+z>=0 && x+z < 7) { |
mikewebkist | 9:7ae675372031 | 62 | LED[x+z]=0; |
mikewebkist | 9:7ae675372031 | 63 | } |
mikewebkist | 9:7ae675372031 | 64 | } |
mikewebkist | 9:7ae675372031 | 65 | |
mikewebkist | 9:7ae675372031 | 66 | } |
mikewebkist | 9:7ae675372031 | 67 | } |
mikewebkist | 9:7ae675372031 | 68 | } |
mikewebkist | 9:7ae675372031 | 69 | |
mikewebkist | 7:c9e707fc8aa3 | 70 | void pileMode(float delayTime) |
mikewebkist | 7:c9e707fc8aa3 | 71 | { |
mikewebkist | 7:c9e707fc8aa3 | 72 | for(int x=0; x<7; x++) |
mikewebkist | 7:c9e707fc8aa3 | 73 | { |
mikewebkist | 7:c9e707fc8aa3 | 74 | for(int y=0; y<(6-x); y++) { |
mikewebkist | 7:c9e707fc8aa3 | 75 | LED[y]=1; |
mikewebkist | 7:c9e707fc8aa3 | 76 | wait(delayTime); |
mikewebkist | 7:c9e707fc8aa3 | 77 | LED[y]=0; |
mikewebkist | 7:c9e707fc8aa3 | 78 | } |
mikewebkist | 7:c9e707fc8aa3 | 79 | LED[6-x]=1; |
mikewebkist | 7:c9e707fc8aa3 | 80 | } |
mikewebkist | 8:41a5757f3bb9 | 81 | wait(delayTime); |
mikewebkist | 7:c9e707fc8aa3 | 82 | for(int x=0; x<7; x++) |
mikewebkist | 7:c9e707fc8aa3 | 83 | { |
mikewebkist | 7:c9e707fc8aa3 | 84 | LED[x] = 0; |
mikewebkist | 7:c9e707fc8aa3 | 85 | } |
mikewebkist | 7:c9e707fc8aa3 | 86 | } |
mikewebkist | 7:c9e707fc8aa3 | 87 | |
mikewebkist | 5:48b81f5fd186 | 88 | void randomMode(float delayTime) |
mikewebkist | 4:eea1a71b9a11 | 89 | { |
mikewebkist | 5:48b81f5fd186 | 90 | for(int x=0; x<128; x++) { |
mikewebkist | 5:48b81f5fd186 | 91 | rndLED = (int) RNG.getByte() % 8; |
mikewebkist | 5:48b81f5fd186 | 92 | LED[rndLED]=1; |
mikewebkist | 6:fe79549495e0 | 93 | wait(0.01); |
mikewebkist | 6:fe79549495e0 | 94 | LED[rndLED]=0; |
mikewebkist | 5:48b81f5fd186 | 95 | wait(delayTime); |
mikewebkist | 5:48b81f5fd186 | 96 | } |
mikewebkist | 5:48b81f5fd186 | 97 | } |
mikewebkist | 5:48b81f5fd186 | 98 | |
mikewebkist | 5:48b81f5fd186 | 99 | void binaryMode(float delayTime) { |
mikewebkist | 3:f3e484ae4439 | 100 | for(int n=0; n<128; n++) { |
mikewebkist | 3:f3e484ae4439 | 101 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 102 | if(n & (1 << b)) { |
mikewebkist | 3:f3e484ae4439 | 103 | LED[6 - b]=1; |
mikewebkist | 3:f3e484ae4439 | 104 | } |
mikewebkist | 3:f3e484ae4439 | 105 | } |
mikewebkist | 5:48b81f5fd186 | 106 | wait(delayTime); |
mikewebkist | 3:f3e484ae4439 | 107 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 108 | LED[b]=0; |
mikewebkist | 3:f3e484ae4439 | 109 | } |
mikewebkist | 3:f3e484ae4439 | 110 | } |
mikewebkist | 5:48b81f5fd186 | 111 | } |
mikewebkist | 5:48b81f5fd186 | 112 | |
mikewebkist | 5:48b81f5fd186 | 113 | void grayMode(float delayTime) { |
mikewebkist | 7:c9e707fc8aa3 | 114 | for(int b=0; b<7; b++) { LED[b]=0; } |
mikewebkist | 7:c9e707fc8aa3 | 115 | |
mikewebkist | 7:c9e707fc8aa3 | 116 | int prev=0; |
mikewebkist | 7:c9e707fc8aa3 | 117 | for(int n=1; n<128; n++) { |
mikewebkist | 7:c9e707fc8aa3 | 118 | int prevGray = (prev >> 1) ^ prev; |
mikewebkist | 4:eea1a71b9a11 | 119 | int gray = (n >> 1) ^ n; |
mikewebkist | 7:c9e707fc8aa3 | 120 | int diffBit = prevGray ^ gray; |
mikewebkist | 4:eea1a71b9a11 | 121 | for(int b=0; b<7; b++) { |
mikewebkist | 7:c9e707fc8aa3 | 122 | if(diffBit & (1 << b)) { |
mikewebkist | 7:c9e707fc8aa3 | 123 | LED[6 - b] = (diffBit & prevGray) ? 0 : 1; |
mikewebkist | 7:c9e707fc8aa3 | 124 | break; |
mikewebkist | 4:eea1a71b9a11 | 125 | } |
mikewebkist | 4:eea1a71b9a11 | 126 | } |
mikewebkist | 7:c9e707fc8aa3 | 127 | prev = n; |
mikewebkist | 5:48b81f5fd186 | 128 | wait(delayTime); |
mikewebkist | 4:eea1a71b9a11 | 129 | } |
mikewebkist | 5:48b81f5fd186 | 130 | } |
mikewebkist | 5:48b81f5fd186 | 131 | |
mikewebkist | 5:48b81f5fd186 | 132 | int main() |
mikewebkist | 5:48b81f5fd186 | 133 | { |
mikewebkist | 5:48b81f5fd186 | 134 | while(1) |
mikewebkist | 5:48b81f5fd186 | 135 | { |
mikewebkist | 5:48b81f5fd186 | 136 | sweep(0.05); |
mikewebkist | 5:48b81f5fd186 | 137 | binaryMode(0.05); |
mikewebkist | 5:48b81f5fd186 | 138 | sweep(0.05); |
mikewebkist | 7:c9e707fc8aa3 | 139 | randomMode(0.05); |
mikewebkist | 5:48b81f5fd186 | 140 | sweep(0.05); |
mikewebkist | 5:48b81f5fd186 | 141 | grayMode(0.05); |
mikewebkist | 6:fe79549495e0 | 142 | sweep(0.05); |
mikewebkist | 7:c9e707fc8aa3 | 143 | bounceMode(0.05); |
mikewebkist | 7:c9e707fc8aa3 | 144 | sweep(0.05); |
mikewebkist | 7:c9e707fc8aa3 | 145 | pileMode(0.05); |
mikewebkist | 9:7ae675372031 | 146 | sweep(0.05); |
mikewebkist | 9:7ae675372031 | 147 | multiSweepMode(0.05); |
mikewebkist | 10:8a901b6d8cfa | 148 | myDeepSleep(); |
Experiment626 | 0:aa0e1ad88af5 | 149 | } |
Experiment626 | 0:aa0e1ad88af5 | 150 | } |