[260] | 1 | #include "r2ca.h"
|
---|
[242] | 2 |
|
---|
| 3 | //#define USE_INTERRUPT
|
---|
| 4 |
|
---|
| 5 | #include <Wire.h>
|
---|
| 6 | #include <Digital_Light_TSL2561.h>
|
---|
| 7 | #include <SeeedOLED.h>
|
---|
[243] | 8 | #include <ChainableLED.h>
|
---|
[242] | 9 |
|
---|
[243] | 10 | #define LED_PIN 4
|
---|
| 11 |
|
---|
[260] | 12 | extern void task1_setup();
|
---|
| 13 | extern void task2_setup();
|
---|
| 14 | extern void task3_setup();
|
---|
| 15 |
|
---|
[243] | 16 | void setup()
|
---|
| 17 | {
|
---|
| 18 | Serial.begin(115200);
|
---|
| 19 | pinMode(LED_PIN, OUTPUT);
|
---|
[260] | 20 |
|
---|
| 21 | task1_setup();
|
---|
| 22 | task2_setup();
|
---|
| 23 | task3_setup();
|
---|
[243] | 24 | }
|
---|
| 25 |
|
---|
| 26 | void 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 |
|
---|
[242] | 35 | #define TOUCH_PIN 3
|
---|
| 36 |
|
---|
| 37 | int is_update_oled;
|
---|
| 38 |
|
---|
[243] | 39 | void task1_setup()
|
---|
[242] | 40 | {
|
---|
| 41 | Wire.begin();
|
---|
| 42 | TSL2561.init();
|
---|
| 43 |
|
---|
| 44 | SeeedOled.init();
|
---|
| 45 | SeeedOled.deactivateScroll();
|
---|
| 46 |
|
---|
| 47 | is_update_oled = 1;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[260] | 50 | void loop1()
|
---|
[243] | 51 | {
|
---|
| 52 | int lux;
|
---|
| 53 |
|
---|
| 54 | lux = TSL2561.readVisibleLux();
|
---|
[242] | 55 | Serial.print("The Light value is: ");
|
---|
[243] | 56 | Serial.println(lux);
|
---|
[242] | 57 |
|
---|
| 58 | if (is_update_oled == 1) {
|
---|
| 59 | wai_sem(OLED_SEM);
|
---|
[243] | 60 | SeeedOled.setTextXY(0, 0);
|
---|
| 61 | SeeedOled.putNumber(lux);
|
---|
| 62 | SeeedOled.putString(" ");
|
---|
[242] | 63 | sig_sem(OLED_SEM);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | delay(1000);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | #ifdef USE_INTERRUPT
|
---|
| 70 | void onTouch(void) {
|
---|
| 71 | Serial.print("hoge");
|
---|
[260] | 72 | iwup_tsk(R2CA_TASK1);
|
---|
[242] | 73 | }
|
---|
| 74 | #endif /* USE_INTERRUPT */
|
---|
| 75 |
|
---|
[243] | 76 | void task2_setup()
|
---|
[242] | 77 | {
|
---|
| 78 | pinMode(TOUCH_PIN, INPUT_PULLUP);
|
---|
| 79 | #ifdef USE_INTERRUPT
|
---|
| 80 | attachInterrupt(TOUCH_PIN, onTouch, CHANGE);
|
---|
| 81 | #endif /* USE_INTERRUPT */
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[260] | 84 | void loop2()
|
---|
[242] | 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 | }
|
---|
[243] | 106 |
|
---|
| 107 | #define NUM_LEDS 1
|
---|
| 108 |
|
---|
| 109 | ChainableLED leds(8, 9, NUM_LEDS);
|
---|
| 110 |
|
---|
| 111 | void task3_setup()
|
---|
| 112 | {
|
---|
| 113 | leds.init();
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | float hue = 0.0;
|
---|
| 117 | boolean up = true;
|
---|
| 118 | int count = 0;
|
---|
| 119 |
|
---|
[260] | 120 | void loop3()
|
---|
[243] | 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 | }
|
---|