mbed Christmas tree using NeoPixel

Dependencies:   mbed

Fork of JBB_SerialLED_test by Junichi Katsu

Revision:
2:435f94e9bb06
Parent:
1:789215018659
Child:
3:98b6f181c935
--- a/main.cpp	Fri Dec 04 14:08:03 2015 +0000
+++ b/main.cpp	Sat Dec 05 05:01:15 2015 +0000
@@ -104,144 +104,55 @@
 
 extern int wakeup;
 
-void led0_event()
-{
-    tapeSet(START_ID + 0, led0_val, led0_val, led0_val);
-    wakeup = 1;
+#define led_event(i) \
+	tapeSet(START_ID + 0, led##i##_val, led##i##_val, led##i##_val); \
+	wakeup = 1; \
+	if (led##i##_val <= 0) \
+        led##i##_val = MAX_LEVEL; \
+    else \
+        led##i##_val -= INTERVAL##i; \
+    if (led##i##_val < 0) \
+        led##i##_val = 0;
 
-    if (led0_val <= 0)
-        led0_val = MAX_LEVEL;
-    else
-        led0_val -= INTERVAL0;
 
-    if (led0_val < 0)
-        led0_val = 0;
+void led0_event() {
+	led_event(0);
 }
 
-void led1_event()
-{
-    tapeSet(START_ID + 1, led1_val, led1_val, led1_val);
-    wakeup = 1;
-
-    if (led1_val <= 0)
-        led1_val = MAX_LEVEL;
-    else
-        led1_val -= INTERVAL1;
-
-    if (led1_val < 0)
-        led1_val = 0;
+void led1_event() {
+	led_event(1);
 }
 
-void led2_event()
-{
-    tapeSet(START_ID + 2, led2_val, led2_val, led2_val);
-    wakeup = 1;
-
-    if (led2_val <= 0)
-        led2_val = MAX_LEVEL;
-    else
-        led2_val -= INTERVAL2;
-
-    if (led2_val < 0)
-        led2_val = 0;
-}
-
-void led3_event()
-{
-    tapeSet(START_ID + 3, led3_val, led3_val, led3_val);
-    wakeup = 1;
-
-    if (led3_val <= 0)
-        led3_val = MAX_LEVEL;
-    else
-        led3_val -= INTERVAL3;
-
-    if (led3_val < 0)
-        led3_val = 0;
+void led2_event() {
+	led_event(2);
 }
 
-void led4_event()
-{
-    tapeSet(START_ID + 4, led4_val, led4_val, led4_val);
-    wakeup = 1;
-
-    if (led4_val <= 0)
-        led4_val = MAX_LEVEL;
-    else
-        led4_val -= INTERVAL4;
-
-    if (led4_val < 0)
-        led4_val = 0;
+void led3_event() {
+	led_event(3);
 }
 
-void led5_event()
-{
-    tapeSet(START_ID + 5, led5_val, led5_val, led5_val);
-    wakeup = 1;
+void led4_event() {
+	led_event(4);
+}
 
-    if (led5_val <= 0)
-        led5_val = MAX_LEVEL;
-    else
-        led5_val -= INTERVAL5;
-
-    if (led5_val < 0)
-        led5_val = 0;
+void led5_event() {
+	led_event(5);
 }
 
-void led6_event()
-{
-    tapeSet(START_ID + 6, led6_val, led6_val, led6_val);
-    wakeup = 1;
-
-    if (led6_val <= 0)
-        led6_val = MAX_LEVEL;
-    else
-        led6_val -= INTERVAL6;
-
-    if (led6_val < 0)
-        led6_val = 0;
+void led6_event() {
+	led_event(6);
 }
 
-void led7_event()
-{
-    tapeSet(START_ID + 7, led7_val, led7_val, led7_val);
-    wakeup = 1;
-
-    if (led7_val <= 0)
-        led7_val = MAX_LEVEL;
-    else
-        led7_val -= INTERVAL7;
-
-    if (led7_val < 0)
-        led7_val = 0;
+void led7_event() {
+	led_event(7);
 }
 
-void led8_event()
-{
-    tapeSet(START_ID + 8, led8_val, led8_val, led8_val);
-    wakeup = 1;
-
-    if (led8_val <= 0)
-        led8_val = MAX_LEVEL;
-    else
-        led8_val -= INTERVAL8;
-
-    if (led8_val < 0)
-        led8_val = 0;
+void led8_event() {
+	led_event(8);
 }
 
-void led9_event()
-{
-    tapeSet(START_ID + 9, led9_val, led9_val, led9_val);
-    wakeup = 1;
-
-    if (led9_val <= 0)
-        led9_val = MAX_LEVEL;
-    else
-        led9_val -= INTERVAL9;
-
-    if (led9_val < 0)
-        led9_val = 0;
+void led9_event() {
+	led_event(9);
 }
 
 void blink_4()