source: rtos_arduino/trunk/examples/MultiTaskText/SingleTask/rca_app.cpp@ 244

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

追加

File size: 2.4 KB
Line 
1#include "rca.h"
2
3//#define LED_BLINK
4//#define CRGB_LED
5//#define TOUCH_SENSE
6#define DLIGHT_READ
7
8#include <Wire.h>
9#include <Digital_Light_TSL2561.h>
10#include <SeeedOLED.h>
11#include <ChainableLED.h>
12
13#define LED_PIN 4
14#define TOUCH_PIN 3
15
16#ifdef LED_BLINK
17
18void setup() {
19 pinMode(LED_PIN, OUTPUT);
20}
21
22void loop() {
23 digitalWrite(LED_PIN, HIGH);
24 delay(1000);
25 digitalWrite(LED_PIN, LOW);
26 delay(1000);
27}
28
29#endif /* LED_BLINK */
30
31#ifdef CRGB_LED
32
33#define NUM_LEDS 1
34ChainableLED leds(8, 9, NUM_LEDS);
35
36void setup() {
37 leds.init();
38}
39
40void loop() {
41 int i;
42 for(i = 0; i < 25; i++){
43 leds.setColorRGB(0, i*10, 0, 0);
44 delay(10);
45 }
46 for(i = 25; i > 0; i--){
47 leds.setColorRGB(0, i*10, 0, 0);
48 delay(10);
49 }
50 for(i = 0; i < 25; i++){
51 leds.setColorRGB(0, 0, i*10, 0);
52 delay(10);
53 }
54 for(i = 25; i > 0; i--){
55 leds.setColorRGB(0, 0, i*10, 0);
56 delay(10);
57 }
58 for(i = 0; i < 25; i++){
59 leds.setColorRGB(0, 0, 0, i*10);
60 delay(10);
61 }
62 for(i = 25; i > 0; i--){
63 leds.setColorRGB(0, 0, 0, i*10);
64 delay(10);
65 }
66}
67#endif /* CRGB_LED */
68
69#ifdef TOUCH_SENSE
70
71int PreTouchValue = 0;
72int TouchState = 0;
73int LEDState = 0;
74
75void setup() {
76 pinMode(TOUCH_PIN, INPUT_PULLUP);
77 pinMode(LED_PIN, OUTPUT);
78 digitalWrite(LED_PIN, LOW);
79}
80
81void loop() {
82 int TouchValue = digitalRead(TOUCH_PIN);
83
84 if ((PreTouchValue == 0) && (TouchValue == 1) && (TouchState = 0)) {
85 TouchState = 1;
86 }
87
88 if ((PreTouchValue == 1) && (TouchValue == 0) && (TouchState = 1)) {
89 TouchState = 0;
90 if (LEDState == 0) {
91 LEDState = 1;
92 digitalWrite(LED_PIN, HIGH);
93 }
94 else {
95 LEDState = 0;
96 digitalWrite(LED_PIN, LOW);
97 }
98 }
99 PreTouchValue = TouchValue;
100}
101
102#endif /* TOUCH_SENSE */
103
104
105#ifdef DLIGHT_READ
106void setup() {
107 Wire.begin();
108 TSL2561.init();
109 SeeedOled.init();
110 SeeedOled.deactivateScroll();
111 SeeedOled.setNormalDisplay();
112 SeeedOled.clearDisplay();
113}
114
115int OLEDCount = 0;
116
117void loop() {
118 int lux = TSL2561.readVisibleLux();
119
120 SeeedOled.setTextXY(0, 0);
121 SeeedOled.putString("Digital Light");
122 SeeedOled.setTextXY(1, 0);
123 SeeedOled.putString("Sensor Value is");
124 SeeedOled.setTextXY(2, 0);
125 SeeedOled.putNumber(lux);
126 SeeedOled.putString(" lux ");
127 SeeedOled.setTextXY(4, 0);
128 SeeedOled.putString("Count is");
129 SeeedOled.setTextXY(5, 0);
130 SeeedOled.putNumber(OLEDCount++);
131}
132#endif /* DLIGHT_READ */
Note: See TracBrowser for help on using the repository browser.