![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
final led
Fork of NeoPixels2 by
main.cpp
- Committer:
- hippi345
- Date:
- 2016-04-14
- Revision:
- 1:d235193680ab
- Parent:
- 0:f38492690f0e
- Child:
- 2:1a511cc48d0d
File content as of revision 1:d235193680ab:
#include "mbed.h" #include "NeoStrip.h" #include "gt.h" #define N 64 #define PATTERNS 3 int hueToRGB(float h); AnalogIn photocell(p16); RawSerial dev(p28,p27); NeoStrip strip(p18, N); DigitalOut myled(LED1); DigitalIn vibration(p15); Serial pc(USBTX,USBRX); int count = 0; int senseValCur; int senseValPre = 1; // timer used for debugging Timer timer; int hueToRGB(float h) { // lots of floating point magic from the internet and scratching my head float r, g, b; if (h > 360) h -= 360; if (h < 0) h += 360; int i = (int)(h / 60.0); float f = (h / 60.0) - i; float q = 1 - f; switch (i % 6) { case 0: r = 1; g = f; b = 0; break; case 1: r = q; g = 1; b = 0; break; case 2: r = 0; g = 1; b = f; break; case 3: r = 0; g = q; b = 1; break; case 4: r = f; g = 0; b = 1; break; case 5: r = 1; g = 0; b = q; break; default: r = 0; g = 0; b = 0; break; } // scale to integers and return the packed value uint8_t R = (uint8_t)(r * 255); uint8_t G = (uint8_t)(g * 255); uint8_t B = (uint8_t)(b * 255); return (R << 16) | (G << 8) | B; } int main() { vibration.mode(PullUp); float bright = 0.2; // 20% is plenty for indoor use strip.setBrightness(bright); // set default brightness while (true) { strip.setBrightness(photocell); myled = vibration.read(); senseValCur = vibration.read(); timer.reset(); // use a timer to measure loop execution time for debugging purposes timer.start(); // for this application, the main loop takes approximately 3ms to run if(senseValCur == 0) { strip.setBrightness(photocell/4); static float dh = 360.0 / N; static float x = 0; for (int i = 0; i < N; i++) {strip.setPixel(i, hueToRGB((dh * i) - x)); x += 1; if (x > 360) x = 0; strip.write(); wait(0.01);} strip.setPixels(0, N, gt_img2); strip.write(); wait(.005); count++; pc.printf("%i\n\r",count); dev.printf("%i\n\r",count); } senseValPre = senseValCur; } }