source: rtos_arduino/trunk/examples/NCESIoT_RTOS/r2ca_app.cpp@ 260

Last change on this file since 260 was 260, checked in by ertl-honda, 8 years ago

マクロ名を更新.
実行モデルを変更.

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