![](/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@11:be76674d2dbd, 2014-09-08 (annotated)
- Committer:
- mikewebkist
- Date:
- Mon Sep 08 16:09:31 2014 +0000
- Revision:
- 11:be76674d2dbd
- Parent:
- 10:8a901b6d8cfa
- Child:
- 12:c94348aca325
Instead of showing all modes, pick one randomly then sleep for 30secs.
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" |
mikewebkist | 11:be76674d2dbd | 3 | #include "WakeUp/WakeUp.h" |
Experiment626 | 0:aa0e1ad88af5 | 4 | |
Experiment626 | 0:aa0e1ad88af5 | 5 | DigitalOut LED[] = {(P0_7), (P0_8), (P0_2), (P0_20), (P1_19), (P0_17), (P0_23)};// declare 7 LEDs |
Experiment626 | 0:aa0e1ad88af5 | 6 | |
mikewebkist | 2:fd6008aa85cd | 7 | int rndLED = 0; |
mikewebkist | 2:fd6008aa85cd | 8 | Random RNG = Random(); |
Experiment626 | 0:aa0e1ad88af5 | 9 | |
mikewebkist | 10:8a901b6d8cfa | 10 | void myDeepSleep() { |
mikewebkist | 10:8a901b6d8cfa | 11 | LPC_PMU->PCON = 0x1; |
mikewebkist | 10:8a901b6d8cfa | 12 | SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; |
mikewebkist | 10:8a901b6d8cfa | 13 | LPC_SYSCON->PDAWAKECFG &= 0xFFFFF800; |
mikewebkist | 10:8a901b6d8cfa | 14 | __WFI(); |
mikewebkist | 10:8a901b6d8cfa | 15 | } |
mikewebkist | 10:8a901b6d8cfa | 16 | |
mikewebkist | 4:eea1a71b9a11 | 17 | void sweep(float delayTime) |
Experiment626 | 0:aa0e1ad88af5 | 18 | { |
mikewebkist | 1:47c61bf9c81e | 19 | for(int x=0; x<7; x++) |
Experiment626 | 0:aa0e1ad88af5 | 20 | { |
mikewebkist | 1:47c61bf9c81e | 21 | LED[x] = 1; |
mikewebkist | 1:47c61bf9c81e | 22 | wait(delayTime); |
Experiment626 | 0:aa0e1ad88af5 | 23 | } |
mikewebkist | 2:fd6008aa85cd | 24 | |
mikewebkist | 2:fd6008aa85cd | 25 | for(int x=6; x>=0; x--) |
Experiment626 | 0:aa0e1ad88af5 | 26 | { |
mikewebkist | 2:fd6008aa85cd | 27 | LED[x] = 0; |
mikewebkist | 1:47c61bf9c81e | 28 | wait(delayTime); |
Experiment626 | 0:aa0e1ad88af5 | 29 | } |
mikewebkist | 4:eea1a71b9a11 | 30 | } |
mikewebkist | 4:eea1a71b9a11 | 31 | |
mikewebkist | 6:fe79549495e0 | 32 | void bounceMode(float delayTime) |
mikewebkist | 6:fe79549495e0 | 33 | { |
mikewebkist | 6:fe79549495e0 | 34 | for(int x=0; x<7; x++) |
mikewebkist | 6:fe79549495e0 | 35 | { |
mikewebkist | 6:fe79549495e0 | 36 | LED[x] = 1; |
mikewebkist | 6:fe79549495e0 | 37 | wait(delayTime); |
mikewebkist | 6:fe79549495e0 | 38 | LED[x] = 0; |
mikewebkist | 6:fe79549495e0 | 39 | } |
mikewebkist | 6:fe79549495e0 | 40 | |
mikewebkist | 6:fe79549495e0 | 41 | for(int x=6; x>=0; x--) |
mikewebkist | 6:fe79549495e0 | 42 | { |
mikewebkist | 6:fe79549495e0 | 43 | LED[x] = 1; |
mikewebkist | 6:fe79549495e0 | 44 | wait(delayTime); |
mikewebkist | 6:fe79549495e0 | 45 | LED[x] = 0; |
mikewebkist | 6:fe79549495e0 | 46 | } |
mikewebkist | 6:fe79549495e0 | 47 | } |
mikewebkist | 6:fe79549495e0 | 48 | |
mikewebkist | 9:7ae675372031 | 49 | void multiSweepMode(float delayTime) |
mikewebkist | 9:7ae675372031 | 50 | { |
mikewebkist | 9:7ae675372031 | 51 | for(int w=1; w<13; w++) |
mikewebkist | 9:7ae675372031 | 52 | { |
mikewebkist | 9:7ae675372031 | 53 | for(int x=1-w; x<13; x++) |
mikewebkist | 9:7ae675372031 | 54 | { |
mikewebkist | 9:7ae675372031 | 55 | for(int z=0; z<w; z++) { |
mikewebkist | 9:7ae675372031 | 56 | if(x+z>=0 && x+z < 7) { |
mikewebkist | 9:7ae675372031 | 57 | LED[x+z]=1; |
mikewebkist | 9:7ae675372031 | 58 | } |
mikewebkist | 9:7ae675372031 | 59 | } |
mikewebkist | 9:7ae675372031 | 60 | wait(delayTime); |
mikewebkist | 9:7ae675372031 | 61 | for(int z=0; z<w; z++) { |
mikewebkist | 9:7ae675372031 | 62 | if(x+z>=0 && x+z < 7) { |
mikewebkist | 9:7ae675372031 | 63 | LED[x+z]=0; |
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 | 9:7ae675372031 | 70 | |
mikewebkist | 7:c9e707fc8aa3 | 71 | void pileMode(float delayTime) |
mikewebkist | 7:c9e707fc8aa3 | 72 | { |
mikewebkist | 7:c9e707fc8aa3 | 73 | for(int x=0; x<7; x++) |
mikewebkist | 7:c9e707fc8aa3 | 74 | { |
mikewebkist | 7:c9e707fc8aa3 | 75 | for(int y=0; y<(6-x); y++) { |
mikewebkist | 7:c9e707fc8aa3 | 76 | LED[y]=1; |
mikewebkist | 7:c9e707fc8aa3 | 77 | wait(delayTime); |
mikewebkist | 7:c9e707fc8aa3 | 78 | LED[y]=0; |
mikewebkist | 7:c9e707fc8aa3 | 79 | } |
mikewebkist | 7:c9e707fc8aa3 | 80 | LED[6-x]=1; |
mikewebkist | 7:c9e707fc8aa3 | 81 | } |
mikewebkist | 8:41a5757f3bb9 | 82 | wait(delayTime); |
mikewebkist | 7:c9e707fc8aa3 | 83 | for(int x=0; x<7; x++) |
mikewebkist | 7:c9e707fc8aa3 | 84 | { |
mikewebkist | 7:c9e707fc8aa3 | 85 | LED[x] = 0; |
mikewebkist | 7:c9e707fc8aa3 | 86 | } |
mikewebkist | 7:c9e707fc8aa3 | 87 | } |
mikewebkist | 7:c9e707fc8aa3 | 88 | |
mikewebkist | 5:48b81f5fd186 | 89 | void randomMode(float delayTime) |
mikewebkist | 4:eea1a71b9a11 | 90 | { |
mikewebkist | 5:48b81f5fd186 | 91 | for(int x=0; x<128; x++) { |
mikewebkist | 5:48b81f5fd186 | 92 | rndLED = (int) RNG.getByte() % 8; |
mikewebkist | 5:48b81f5fd186 | 93 | LED[rndLED]=1; |
mikewebkist | 6:fe79549495e0 | 94 | wait(0.01); |
mikewebkist | 6:fe79549495e0 | 95 | LED[rndLED]=0; |
mikewebkist | 5:48b81f5fd186 | 96 | wait(delayTime); |
mikewebkist | 5:48b81f5fd186 | 97 | } |
mikewebkist | 5:48b81f5fd186 | 98 | } |
mikewebkist | 5:48b81f5fd186 | 99 | |
mikewebkist | 5:48b81f5fd186 | 100 | void binaryMode(float delayTime) { |
mikewebkist | 3:f3e484ae4439 | 101 | for(int n=0; n<128; n++) { |
mikewebkist | 3:f3e484ae4439 | 102 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 103 | if(n & (1 << b)) { |
mikewebkist | 3:f3e484ae4439 | 104 | LED[6 - b]=1; |
mikewebkist | 3:f3e484ae4439 | 105 | } |
mikewebkist | 3:f3e484ae4439 | 106 | } |
mikewebkist | 5:48b81f5fd186 | 107 | wait(delayTime); |
mikewebkist | 3:f3e484ae4439 | 108 | for(int b=0; b<7; b++) { |
mikewebkist | 3:f3e484ae4439 | 109 | LED[b]=0; |
mikewebkist | 3:f3e484ae4439 | 110 | } |
mikewebkist | 3:f3e484ae4439 | 111 | } |
mikewebkist | 5:48b81f5fd186 | 112 | } |
mikewebkist | 5:48b81f5fd186 | 113 | |
mikewebkist | 5:48b81f5fd186 | 114 | void grayMode(float delayTime) { |
mikewebkist | 7:c9e707fc8aa3 | 115 | for(int b=0; b<7; b++) { LED[b]=0; } |
mikewebkist | 7:c9e707fc8aa3 | 116 | |
mikewebkist | 7:c9e707fc8aa3 | 117 | int prev=0; |
mikewebkist | 7:c9e707fc8aa3 | 118 | for(int n=1; n<128; n++) { |
mikewebkist | 7:c9e707fc8aa3 | 119 | int prevGray = (prev >> 1) ^ prev; |
mikewebkist | 4:eea1a71b9a11 | 120 | int gray = (n >> 1) ^ n; |
mikewebkist | 7:c9e707fc8aa3 | 121 | int diffBit = prevGray ^ gray; |
mikewebkist | 4:eea1a71b9a11 | 122 | for(int b=0; b<7; b++) { |
mikewebkist | 7:c9e707fc8aa3 | 123 | if(diffBit & (1 << b)) { |
mikewebkist | 7:c9e707fc8aa3 | 124 | LED[6 - b] = (diffBit & prevGray) ? 0 : 1; |
mikewebkist | 7:c9e707fc8aa3 | 125 | break; |
mikewebkist | 4:eea1a71b9a11 | 126 | } |
mikewebkist | 4:eea1a71b9a11 | 127 | } |
mikewebkist | 7:c9e707fc8aa3 | 128 | prev = n; |
mikewebkist | 5:48b81f5fd186 | 129 | wait(delayTime); |
mikewebkist | 4:eea1a71b9a11 | 130 | } |
mikewebkist | 5:48b81f5fd186 | 131 | } |
mikewebkist | 5:48b81f5fd186 | 132 | |
mikewebkist | 5:48b81f5fd186 | 133 | int main() |
mikewebkist | 5:48b81f5fd186 | 134 | { |
mikewebkist | 5:48b81f5fd186 | 135 | while(1) |
mikewebkist | 5:48b81f5fd186 | 136 | { |
mikewebkist | 5:48b81f5fd186 | 137 | sweep(0.05); |
mikewebkist | 11:be76674d2dbd | 138 | int x = (int) RNG.getByte() % 6; |
mikewebkist | 11:be76674d2dbd | 139 | switch(x) { |
mikewebkist | 11:be76674d2dbd | 140 | case 0: |
mikewebkist | 11:be76674d2dbd | 141 | binaryMode(0.05); |
mikewebkist | 11:be76674d2dbd | 142 | break; |
mikewebkist | 11:be76674d2dbd | 143 | case 1: |
mikewebkist | 11:be76674d2dbd | 144 | randomMode(0.05); |
mikewebkist | 11:be76674d2dbd | 145 | break; |
mikewebkist | 11:be76674d2dbd | 146 | case 2: |
mikewebkist | 11:be76674d2dbd | 147 | grayMode(0.05); |
mikewebkist | 11:be76674d2dbd | 148 | break; |
mikewebkist | 11:be76674d2dbd | 149 | case 3: |
mikewebkist | 11:be76674d2dbd | 150 | bounceMode(0.05); |
mikewebkist | 11:be76674d2dbd | 151 | break; |
mikewebkist | 11:be76674d2dbd | 152 | case 4: |
mikewebkist | 11:be76674d2dbd | 153 | pileMode(0.05); |
mikewebkist | 11:be76674d2dbd | 154 | break; |
mikewebkist | 11:be76674d2dbd | 155 | case 5: |
mikewebkist | 11:be76674d2dbd | 156 | multiSweepMode(0.05); |
mikewebkist | 11:be76674d2dbd | 157 | break; |
mikewebkist | 11:be76674d2dbd | 158 | } |
mikewebkist | 6:fe79549495e0 | 159 | sweep(0.05); |
mikewebkist | 11:be76674d2dbd | 160 | WakeUp::set_ms(30000); |
mikewebkist | 10:8a901b6d8cfa | 161 | myDeepSleep(); |
Experiment626 | 0:aa0e1ad88af5 | 162 | } |
Experiment626 | 0:aa0e1ad88af5 | 163 | } |