Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Wio_3G_HTTP-GET-example by
main.cpp@73:d47320bcc568, 2018-08-08 (annotated)
- Committer:
- MACRUM
- Date:
- Wed Aug 08 07:40:47 2018 +0000
- Revision:
- 73:d47320bcc568
- Parent:
- 72:aa14c091f860
- Child:
- 74:847e5dc7b4d5
Add more libraries
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Jonathan Austin |
0:2757d7abb7d9 | 1 | #include "mbed.h" |
| MACRUM | 71:7d17edde2e03 | 2 | #include "Grove_LCD_RGB_Backlight.h" |
| MACRUM | 72:aa14c091f860 | 3 | #include "Grove_temperature.h" |
| MACRUM | 73:d47320bcc568 | 4 | #include "WS2812.h" |
| MACRUM | 73:d47320bcc568 | 5 | #include "PixelArray.h" |
| MACRUM | 73:d47320bcc568 | 6 | #include "Servo.h" |
| MACRUM | 73:d47320bcc568 | 7 | |
| MACRUM | 73:d47320bcc568 | 8 | #if !defined(TARGET_WIO_3G) |
| MACRUM | 73:d47320bcc568 | 9 | #error Selected target is not supported. |
| MACRUM | 73:d47320bcc568 | 10 | #endif |
| MACRUM | 70:cb6d36218441 | 11 | |
| MACRUM | 70:cb6d36218441 | 12 | #define D20 (PB_4) |
| MACRUM | 70:cb6d36218441 | 13 | #define D19 (PB_3) |
| MACRUM | 70:cb6d36218441 | 14 | |
| MACRUM | 73:d47320bcc568 | 15 | // on-board resources |
| MACRUM | 73:d47320bcc568 | 16 | Serial pc(USBTX, USBRX, 115200); |
| MACRUM | 70:cb6d36218441 | 17 | DigitalOut GrovePower(PB_10, 1); |
| MACRUM | 73:d47320bcc568 | 18 | |
| MACRUM | 73:d47320bcc568 | 19 | #define WS2812_BUF 150 |
| MACRUM | 73:d47320bcc568 | 20 | #define NUM_COLORS 6 |
| MACRUM | 73:d47320bcc568 | 21 | #define NUM_LEDS_PER_COLOR 10 |
| MACRUM | 73:d47320bcc568 | 22 | |
| MACRUM | 73:d47320bcc568 | 23 | #define H0 8 |
| MACRUM | 73:d47320bcc568 | 24 | #define L0 32 |
| MACRUM | 73:d47320bcc568 | 25 | #define H1 17 |
| MACRUM | 73:d47320bcc568 | 26 | #define L1 32 |
| MACRUM | 73:d47320bcc568 | 27 | |
| MACRUM | 73:d47320bcc568 | 28 | DigitalOut LEDPower(PE_8, 1); |
| MACRUM | 73:d47320bcc568 | 29 | PixelArray px(WS2812_BUF); |
| MACRUM | 73:d47320bcc568 | 30 | WS2812 ws(PB_1, 1, H0, L0, H1, L1); |
| MACRUM | 73:d47320bcc568 | 31 | #if 0 |
| MACRUM | 73:d47320bcc568 | 32 | // Grove sensors |
| MACRUM | 70:cb6d36218441 | 33 | DigitalOut led1(D38); |
| MACRUM | 73:d47320bcc568 | 34 | AnalogIn ain(A6); // angle or light sensor |
| MACRUM | 73:d47320bcc568 | 35 | InterruptIn btn(D20); // button or touch sensor |
| MACRUM | 73:d47320bcc568 | 36 | Grove_LCD_RGB_Backlight lcd(I2C_SDA, I2C_SCL); |
| MACRUM | 72:aa14c091f860 | 37 | Grove_temperature temp(A4); |
| MACRUM | 73:d47320bcc568 | 38 | #endif |
| MACRUM | 71:7d17edde2e03 | 39 | uint32_t button = 0; |
| MACRUM | 70:cb6d36218441 | 40 | |
| MACRUM | 70:cb6d36218441 | 41 | |
| MACRUM | 70:cb6d36218441 | 42 | void push() |
| MACRUM | 70:cb6d36218441 | 43 | { |
| MACRUM | 71:7d17edde2e03 | 44 | button++; |
| MACRUM | 70:cb6d36218441 | 45 | } |
| Jonathan Austin |
0:2757d7abb7d9 | 46 | |
| MACRUM | 73:d47320bcc568 | 47 | #if 0 |
| MACRUM | 73:d47320bcc568 | 48 | |
| Jonathan Austin |
1:846c97078558 | 49 | // main() runs in its own thread in the OS |
| MACRUM | 70:cb6d36218441 | 50 | int main() |
| MACRUM | 70:cb6d36218441 | 51 | { |
| MACRUM | 73:d47320bcc568 | 52 | char buf[20]; |
| MACRUM | 73:d47320bcc568 | 53 | btn.fall(push); // set interrupt handler |
| MACRUM | 70:cb6d36218441 | 54 | |
| MACRUM | 73:d47320bcc568 | 55 | lcd.clear(); |
| MACRUM | 73:d47320bcc568 | 56 | lcd.setRGB(0xff, 0x00, 0x00); |
| MACRUM | 73:d47320bcc568 | 57 | lcd.locate(0, 0); |
| MACRUM | 73:d47320bcc568 | 58 | lcd.print("Hello World!"); |
| MACRUM | 73:d47320bcc568 | 59 | lcd.locate(0, 1); |
| MACRUM | 73:d47320bcc568 | 60 | |
| MACRUM | 73:d47320bcc568 | 61 | #if 0 |
| MACRUM | 73:d47320bcc568 | 62 | ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling |
| MACRUM | 73:d47320bcc568 | 63 | int array[4] = (0xff, 0, 0, 0); |
| MACRUM | 73:d47320bcc568 | 64 | ws.write(array); |
| MACRUM | 73:d47320bcc568 | 65 | #endif |
| MACRUM | 71:7d17edde2e03 | 66 | |
| MACRUM | 70:cb6d36218441 | 67 | int cnt = 0; |
| MACRUM | 73:d47320bcc568 | 68 | pc.printf("hello, Mbed world\n"); |
| MACRUM | 73:d47320bcc568 | 69 | |
| Jonathan Austin |
0:2757d7abb7d9 | 70 | while (true) { |
| MACRUM | 73:d47320bcc568 | 71 | pc.printf("count = %4d, button = %d, analog = %2.2f, temp = %2.2f\n", cnt++, button, ain.read(), temp.getTemperature()); |
| MACRUM | 73:d47320bcc568 | 72 | sprintf(buf, "L=%2.2f, T=%2.2f", ain.read(), temp.getTemperature()); |
| MACRUM | 73:d47320bcc568 | 73 | lcd.setRGB(0xff, (255*ain.read()), 0x00); |
| MACRUM | 73:d47320bcc568 | 74 | lcd.locate(0, 1); |
| MACRUM | 73:d47320bcc568 | 75 | lcd.print(buf); |
| Jonathan Austin |
0:2757d7abb7d9 | 76 | led1 = !led1; |
| mbed_official | 22:af9dcf379926 | 77 | wait(0.5); |
| Jonathan Austin |
0:2757d7abb7d9 | 78 | } |
| Jonathan Austin |
0:2757d7abb7d9 | 79 | } |
| MACRUM | 73:d47320bcc568 | 80 | |
| MACRUM | 73:d47320bcc568 | 81 | #else |
| MACRUM | 73:d47320bcc568 | 82 | int main() |
| MACRUM | 73:d47320bcc568 | 83 | { |
| MACRUM | 73:d47320bcc568 | 84 | pc.printf("NeoPixel test.\n"); |
| MACRUM | 73:d47320bcc568 | 85 | pc.printf("%2d, %2d, %2d, %2d\n", H0, L0, H1, L1); |
| MACRUM | 73:d47320bcc568 | 86 | |
| MACRUM | 73:d47320bcc568 | 87 | ws.useII(WS2812::PER_PIXEL); // use per-pixel intensity scaling |
| MACRUM | 73:d47320bcc568 | 88 | |
| MACRUM | 73:d47320bcc568 | 89 | // set up the colours we want to draw with |
| MACRUM | 73:d47320bcc568 | 90 | int colorbuf[NUM_COLORS] = {0x2f0000,0x2f2f00,0x002f00,0x002f2f,0x00002f,0x2f002f}; |
| MACRUM | 73:d47320bcc568 | 91 | |
| MACRUM | 73:d47320bcc568 | 92 | // for each of the colours (j) write out 10 of them |
| MACRUM | 73:d47320bcc568 | 93 | // the pixels are written at the colour*10, plus the colour position |
| MACRUM | 73:d47320bcc568 | 94 | // all modulus 60 so it wraps around |
| MACRUM | 73:d47320bcc568 | 95 | for (int i = 0; i < WS2812_BUF; i++) { |
| MACRUM | 73:d47320bcc568 | 96 | px.Set(i, colorbuf[(i / NUM_LEDS_PER_COLOR) % NUM_COLORS]); |
| MACRUM | 73:d47320bcc568 | 97 | } |
| MACRUM | 73:d47320bcc568 | 98 | |
| MACRUM | 73:d47320bcc568 | 99 | // now all the colours are computed, add a fade effect using intensity scaling |
| MACRUM | 73:d47320bcc568 | 100 | // compute and write the II value for each pixel |
| MACRUM | 73:d47320bcc568 | 101 | for (int j=0; j<WS2812_BUF; j++) { |
| MACRUM | 73:d47320bcc568 | 102 | // px.SetI(pixel position, II value) |
| MACRUM | 73:d47320bcc568 | 103 | px.SetI(j%WS2812_BUF, 0xf+(0xf*(j%NUM_LEDS_PER_COLOR))); |
| MACRUM | 73:d47320bcc568 | 104 | } |
| MACRUM | 73:d47320bcc568 | 105 | |
| MACRUM | 73:d47320bcc568 | 106 | |
| MACRUM | 73:d47320bcc568 | 107 | // Now the buffer is written, rotate it |
| MACRUM | 73:d47320bcc568 | 108 | // by writing it out with an increasing offset |
| MACRUM | 73:d47320bcc568 | 109 | while (1) { |
| MACRUM | 73:d47320bcc568 | 110 | for (int z=WS2812_BUF; z >= 0 ; z--) { |
| MACRUM | 73:d47320bcc568 | 111 | ws.write_offsets(px.getBuf(),z,z,z); |
| MACRUM | 73:d47320bcc568 | 112 | wait(0.075); |
| MACRUM | 73:d47320bcc568 | 113 | } |
| MACRUM | 73:d47320bcc568 | 114 | } |
| MACRUM | 73:d47320bcc568 | 115 | |
| MACRUM | 73:d47320bcc568 | 116 | } |
| MACRUM | 73:d47320bcc568 | 117 | #endif |
| MACRUM | 73:d47320bcc568 | 118 |
