source: rtos_arduino/trunk/examples/MultiTaskText/Interrupt/r2ca_app.cpp@ 260

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

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

File size: 1.4 KB
Line 
1#include "r2ca.h"
2
3#include <Wire.h>
4#include <Digital_Light_TSL2561.h>
5#include <SeeedOLED.h>
6
7#define TOUCH_PIN 3
8#define LED_PIN 4
9
10int PreTouchValue = 0;
11int TouchState = 0;
12int LEDState = 0;
13
14extern void CheckTouch(void);
15
16void setup() {
17 Wire.begin();
18 TSL2561.init();
19 SeeedOled.init();
20 SeeedOled.deactivateScroll();
21 SeeedOled.setNormalDisplay();
22 SeeedOled.clearDisplay();
23
24 pinMode(TOUCH_PIN, INPUT_PULLUP);
25 pinMode(LED_PIN, OUTPUT);
26 digitalWrite(LED_PIN, LOW);
27 attachInterrupt(TOUCH_PIN, CheckTouch, CHANGE);
28}
29
30int OLEDCount = 0;
31
32void CheckTouch(){
33 int TouchValue = digitalRead(TOUCH_PIN);
34
35 if ((PreTouchValue == 0) && (TouchValue == 1) && (TouchState == 0)) {
36 TouchState = 1;
37 }
38
39 if ((PreTouchValue == 1) && (TouchValue == 0) && (TouchState == 1)) {
40 TouchState = 0;
41 iwup_tsk(R2CA_TASK1);
42 }
43 PreTouchValue = TouchValue;
44}
45
46void loop() {
47 int lux;
48
49 lux = TSL2561.readVisibleLux();
50
51 SeeedOled.setTextXY(0, 0);
52 SeeedOled.putString("Digital Light");
53 SeeedOled.setTextXY(1, 0);
54 SeeedOled.putString("Sensor Value is");
55 SeeedOled.setTextXY(2, 0);
56 SeeedOled.putNumber(lux);
57 SeeedOled.putString(" lux ");
58 SeeedOled.setTextXY(4, 0);
59 SeeedOled.putString("Count is");
60 SeeedOled.setTextXY(5, 0);
61 SeeedOled.putNumber(OLEDCount++);
62 SeeedOled.putString(" ");
63}
64
65void loop1() {
66 slp_tsk();
67
68 digitalWrite(LED_PIN, HIGH);
69 dly_tsk(2000);
70 digitalWrite(LED_PIN, LOW);
71}
Note: See TracBrowser for help on using the repository browser.