1 | #include "rca.h"
|
---|
2 |
|
---|
3 | //#define USE_INTERRUPT
|
---|
4 |
|
---|
5 | #include <Wire.h>
|
---|
6 | #include <Digital_Light_TSL2561.h>
|
---|
7 | #include <SeeedOLED.h>
|
---|
8 | #include <ChainableLED.h>
|
---|
9 |
|
---|
10 | #define LED_PIN 4
|
---|
11 |
|
---|
12 | void setup()
|
---|
13 | {
|
---|
14 | Serial.begin(115200);
|
---|
15 | pinMode(LED_PIN, OUTPUT);
|
---|
16 | }
|
---|
17 |
|
---|
18 | void loop()
|
---|
19 | {
|
---|
20 | digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
|
---|
21 | delay(1000); // wait for a second
|
---|
22 | digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW
|
---|
23 | delay(1000); // wait for a second
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | #define TOUCH_PIN 3
|
---|
28 |
|
---|
29 | int is_update_oled;
|
---|
30 |
|
---|
31 | void task1_setup()
|
---|
32 | {
|
---|
33 | Wire.begin();
|
---|
34 | TSL2561.init();
|
---|
35 |
|
---|
36 | SeeedOled.init();
|
---|
37 | SeeedOled.deactivateScroll();
|
---|
38 |
|
---|
39 | is_update_oled = 1;
|
---|
40 | }
|
---|
41 |
|
---|
42 | void task1_loop()
|
---|
43 | {
|
---|
44 | int lux;
|
---|
45 |
|
---|
46 | lux = TSL2561.readVisibleLux();
|
---|
47 | Serial.print("The Light value is: ");
|
---|
48 | Serial.println(lux);
|
---|
49 |
|
---|
50 | if (is_update_oled == 1) {
|
---|
51 | wai_sem(OLED_SEM);
|
---|
52 | SeeedOled.setTextXY(0, 0);
|
---|
53 | SeeedOled.putNumber(lux);
|
---|
54 | SeeedOled.putString(" ");
|
---|
55 | sig_sem(OLED_SEM);
|
---|
56 | }
|
---|
57 |
|
---|
58 | delay(1000);
|
---|
59 | }
|
---|
60 |
|
---|
61 | #ifdef USE_INTERRUPT
|
---|
62 | void onTouch(void) {
|
---|
63 | Serial.print("hoge");
|
---|
64 | iwup_tsk(RCA_TASK1);
|
---|
65 | }
|
---|
66 | #endif /* USE_INTERRUPT */
|
---|
67 |
|
---|
68 | void task2_setup()
|
---|
69 | {
|
---|
70 | pinMode(TOUCH_PIN, INPUT_PULLUP);
|
---|
71 | #ifdef USE_INTERRUPT
|
---|
72 | attachInterrupt(TOUCH_PIN, onTouch, CHANGE);
|
---|
73 | #endif /* USE_INTERRUPT */
|
---|
74 | }
|
---|
75 |
|
---|
76 | void task2_loop()
|
---|
77 | {
|
---|
78 | #ifdef USE_INTERRUPT
|
---|
79 | slp_tsk();
|
---|
80 | #else /* USE_INTERRUPT */
|
---|
81 | delay(1);
|
---|
82 | #endif /* USE_INTERRUPT */
|
---|
83 |
|
---|
84 | int TouchSensorValue = digitalRead(TOUCH_PIN);
|
---|
85 |
|
---|
86 | if(TouchSensorValue==1) {
|
---|
87 | is_update_oled = 0;
|
---|
88 | wai_sem(OLED_SEM);
|
---|
89 | SeeedOled.setInverseDisplay();
|
---|
90 | sig_sem(OLED_SEM);
|
---|
91 | }else{
|
---|
92 | is_update_oled = 1;
|
---|
93 | wai_sem(OLED_SEM);
|
---|
94 | SeeedOled.setNormalDisplay();
|
---|
95 | sig_sem(OLED_SEM);
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | #define NUM_LEDS 1
|
---|
100 |
|
---|
101 | ChainableLED leds(8, 9, NUM_LEDS);
|
---|
102 |
|
---|
103 | void task3_setup()
|
---|
104 | {
|
---|
105 | leds.init();
|
---|
106 | }
|
---|
107 |
|
---|
108 | float hue = 0.0;
|
---|
109 | boolean up = true;
|
---|
110 | int count = 0;
|
---|
111 |
|
---|
112 | void task3_loop()
|
---|
113 | {
|
---|
114 | for (byte i=0; i<NUM_LEDS; i++)
|
---|
115 | leds.setColorHSB(i, hue, 1.0, 0.5);
|
---|
116 |
|
---|
117 | delay(50);
|
---|
118 |
|
---|
119 | if (up)
|
---|
120 | hue+= 0.025;
|
---|
121 | else
|
---|
122 | hue-= 0.025;
|
---|
123 |
|
---|
124 | if (hue>=1.0 && up)
|
---|
125 | up = false;
|
---|
126 | else if (hue<=0.0 && !up)
|
---|
127 | up = true;
|
---|
128 | }
|
---|