diff --git a/gesturedemoCC03_CS11/LOOP.ino b/gesturedemoCC03_CS11/LOOP.ino new file mode 100644 index 0000000..155892b --- /dev/null +++ b/gesturedemoCC03_CS11/LOOP.ino @@ -0,0 +1,7 @@ +void main_program(void) { + while (1) { + delay(0); + TaskScheduler(); + } +} + diff --git a/gesturedemoCC03_CS11/MAIN.ino b/gesturedemoCC03_CS11/MAIN.ino new file mode 100644 index 0000000..9cf130f --- /dev/null +++ b/gesturedemoCC03_CS11/MAIN.ino @@ -0,0 +1,37 @@ +void main_code(void) { + apds.readProximity(proximity_data); + OD01.println("Move your hand to"); + OD01.println("and away from"); + OD01.println("the sensor"); + int y = map(proximity_data, 0, 255, 0, 500); + if ((y > 0) && (y < 125)) { + OC01.write(OUT0, HIGH); + OC01.write(OUT1, LOW); + OC01.write(OUT2, LOW); + OC01.write(OUT3, LOW); + } else if ((y > 125) && (y < 250)) { + OC01.write(OUT0, HIGH); + OC01.write(OUT1, HIGH); + OC01.write(OUT2, LOW); + OC01.write(OUT3, LOW); + } + else if ((y > 250) && (y < 375)) { + OC01.write(OUT0, HIGH); + OC01.write(OUT1, HIGH); + OC01.write(OUT2, HIGH); + OC01.write(OUT3, LOW); + } + else if ((y > 375) && (y < 500)) { + OC01.write(OUT0, HIGH); + OC01.write(OUT1, HIGH); + OC01.write(OUT2, HIGH); + OC01.write(OUT3, HIGH); + } else if (y == 0) { + OC01.write(OUT0, LOW); + OC01.write(OUT1, LOW); + OC01.write(OUT2, LOW); + OC01.write(OUT3, LOW); + } + OD01.println(y); +} + diff --git a/gesturedemoCC03_CS11/RGB.ino b/gesturedemoCC03_CS11/RGB.ino new file mode 100644 index 0000000..dd6624a --- /dev/null +++ b/gesturedemoCC03_CS11/RGB.ino @@ -0,0 +1,60 @@ +void red_fade(const long interval, int LED, int limit, int increment) { + currentMilli = millis(); + if (currentMilli - previousMilli1 >= interval) { + previousMilli1 = currentMilli; + if (fade_flag1 == true) { + LED_state1 += increment; + if (LED_state1 == limit) { + fade_flag1 = false; + } + } + if (fade_flag1 == false) { + LED_state1 -= increment; + if (LED_state1 == 0) { + fade_flag1 = true; + ledID++; + } + } + } + analogWrite(LED, LED_state1); +} +void blue_fade(const long interval, int LED, int limit, int increment) { + currentMilli = millis(); + if (currentMilli - previousMilli2 >= interval) { + previousMilli2 = currentMilli; + if (fade_flag2 == true) { + LED_state2 += increment; + if (LED_state2 == limit) { + fade_flag2 = false; + } + } + if (fade_flag2 == false) { + LED_state2 -= increment; + if (LED_state2 == 0) { + fade_flag2 = true; + ledID = 0; + } + } + } + analogWrite(LED, LED_state2); +} +void green_fade(const long interval, int LED, int limit, int increment) { + currentMilli = millis(); + if (currentMilli - previousMilli3 >= interval) { + previousMilli3 = currentMilli; + if (fade_flag3 == true) { + LED_state3 += increment; + if (LED_state3 == limit) { + fade_flag3 = false; + } + } + if (fade_flag3 == false) { + LED_state3 -= increment; + if (LED_state3 == 0) { + fade_flag3 = true; + ledID++; + } + } + } + analogWrite(LED, LED_state3); +} diff --git a/gesturedemoCC03_CS11/SETUP.ino b/gesturedemoCC03_CS11/SETUP.ino new file mode 100644 index 0000000..65d492d --- /dev/null +++ b/gesturedemoCC03_CS11/SETUP.ino @@ -0,0 +1,53 @@ +void setup_program(void) { + + #if defined(ESP8266) + WiFi.forceSleepBegin(); + Wire.begin(2, 14); + Wire.setClockStretchLimit(15000); + +#elif defined(ARDUINO_SAMD_ZERO) + Wire.begin(); + +#elif defined(ARDUINO_AVR_PRO) + Wire.begin(); + +#elif defined(ESP32) + Wire.begin(); + +#endif + + // start sensor + apds.setProximityGain(PGAIN_1X); + apds.enableProximitySensor(false); + apds.setProximityIntLowThreshold(4); + OC01.begin(); + + + // start oled + OLED.begin(); + + // clear oled + OD01.clear(); + + // set output leds + pinMode(CW01_RED, OUTPUT); + pinMode(CW01_GREEN, OUTPUT); + pinMode(CW01_BLUE, OUTPUT); + + // turn rgb on + digitalWrite(CW01_RED, HIGH); + digitalWrite(CW01_GREEN, HIGH); + digitalWrite(CW01_BLUE, HIGH); + + delay(2000); + + // turn rgb off + digitalWrite(CW01_RED, LOW); + digitalWrite(CW01_GREEN, LOW); + digitalWrite(CW01_BLUE, LOW); + + delay(1000); + t.tick_main = millis(); + t.tick_poll = millis(); +} + diff --git a/gesturedemoCC03_CS11/TASKS.ino b/gesturedemoCC03_CS11/TASKS.ino new file mode 100644 index 0000000..a2aa6f7 --- /dev/null +++ b/gesturedemoCC03_CS11/TASKS.ino @@ -0,0 +1,20 @@ +void TaskScheduler(void) { + if (ledID == 0) { + red_fade(30, CW01_RED, 255, 5); + } else if (ledID == 1) { + green_fade(30, CW01_GREEN, 255, 5); + } else if (ledID == 2) { + blue_fade(30, CW01_BLUE, 255, 5); + } + + if ((millis() - t.tick_main) > 1000) { + OD01.clear(); + main_code(); + t.tick_main = millis(); + } + if ((millis() - t.tick_poll) > 30) { + // poll sensor + + t.tick_poll = millis(); + } +} diff --git a/gesturedemoCC03_CS11/TIMER_CTRL.h b/gesturedemoCC03_CS11/TIMER_CTRL.h new file mode 100644 index 0000000..c54afa9 --- /dev/null +++ b/gesturedemoCC03_CS11/TIMER_CTRL.h @@ -0,0 +1,10 @@ +#ifndef timer_h +#define timer_h + +struct TIMER_CTRL { + unsigned long tick_main; + unsigned long tick_poll; +}t; + +#endif + diff --git a/gesturedemoCC03_CS11/gesturedemoCC03_CS11.ino b/gesturedemoCC03_CS11/gesturedemoCC03_CS11.ino new file mode 100644 index 0000000..77d4828 --- /dev/null +++ b/gesturedemoCC03_CS11/gesturedemoCC03_CS11.ino @@ -0,0 +1,63 @@ +#include + +#include + +#include +#include +#include "TIMER_CTRL.h" +#include +#include + +#if defined(ESP8266) +#define RED RED +#define GREEN GREEN +#define BLUE BLUE +#include +#define Serial Serial + +#elif defined(ARDUINO_SAMD_ZERO) +#define RED CC03_RED +#define GREEN CC03_GREEN +#define BLUE CC03_BLUE +#define Serial SerialUSB + +#elif defined(ARDUINO_AVR_PRO) +#define RED CC01_RED +#define GREEN CC01_GREEN +#define BLUE CC01_BLUE +#define Serial Serial + +#elif defined(ESP32) +#define RED CW02_RED +#define GREEN CW02_GREEN +#define BLUE CW02_BLUE +#define Serial Serial +#endif + +xOC01 OC01; + +SparkFun_APDS9960 apds = SparkFun_APDS9960(); +uint8_t proximity_data = 0; + +unsigned long currentMilli = 0; +int ledID = 0; +bool fade_flag1 =true; +unsigned long previousMilli1 = 0; // timing variable for LEDS +int LED_state1 = 0; +bool fade_flag2 = true; +unsigned long previousMilli2 = 0; // timing variable for LEDS +int LED_state2 = 0; +bool fade_flag3 = true; +unsigned long previousMilli3 = 0; // timing variable for LEDS +int LED_state3 = 0; + + +void setup() { + // put your setup code here, to run once: + setup_program(); +} + +void loop() { + // put your main code here, to run repeatedly: + main_program(); +} diff --git a/gesturedemoCW01/LOOP.ino b/gesturedemoCW01/LOOP.ino new file mode 100644 index 0000000..155892b --- /dev/null +++ b/gesturedemoCW01/LOOP.ino @@ -0,0 +1,7 @@ +void main_program(void) { + while (1) { + delay(0); + TaskScheduler(); + } +} + diff --git a/gesturedemoCW01/MAIN.ino b/gesturedemoCW01/MAIN.ino new file mode 100644 index 0000000..9cf130f --- /dev/null +++ b/gesturedemoCW01/MAIN.ino @@ -0,0 +1,37 @@ +void main_code(void) { + apds.readProximity(proximity_data); + OD01.println("Move your hand to"); + OD01.println("and away from"); + OD01.println("the sensor"); + int y = map(proximity_data, 0, 255, 0, 500); + if ((y > 0) && (y < 125)) { + OC01.write(OUT0, HIGH); + OC01.write(OUT1, LOW); + OC01.write(OUT2, LOW); + OC01.write(OUT3, LOW); + } else if ((y > 125) && (y < 250)) { + OC01.write(OUT0, HIGH); + OC01.write(OUT1, HIGH); + OC01.write(OUT2, LOW); + OC01.write(OUT3, LOW); + } + else if ((y > 250) && (y < 375)) { + OC01.write(OUT0, HIGH); + OC01.write(OUT1, HIGH); + OC01.write(OUT2, HIGH); + OC01.write(OUT3, LOW); + } + else if ((y > 375) && (y < 500)) { + OC01.write(OUT0, HIGH); + OC01.write(OUT1, HIGH); + OC01.write(OUT2, HIGH); + OC01.write(OUT3, HIGH); + } else if (y == 0) { + OC01.write(OUT0, LOW); + OC01.write(OUT1, LOW); + OC01.write(OUT2, LOW); + OC01.write(OUT3, LOW); + } + OD01.println(y); +} + diff --git a/gesturedemoCW01/RGB.ino b/gesturedemoCW01/RGB.ino new file mode 100644 index 0000000..dd6624a --- /dev/null +++ b/gesturedemoCW01/RGB.ino @@ -0,0 +1,60 @@ +void red_fade(const long interval, int LED, int limit, int increment) { + currentMilli = millis(); + if (currentMilli - previousMilli1 >= interval) { + previousMilli1 = currentMilli; + if (fade_flag1 == true) { + LED_state1 += increment; + if (LED_state1 == limit) { + fade_flag1 = false; + } + } + if (fade_flag1 == false) { + LED_state1 -= increment; + if (LED_state1 == 0) { + fade_flag1 = true; + ledID++; + } + } + } + analogWrite(LED, LED_state1); +} +void blue_fade(const long interval, int LED, int limit, int increment) { + currentMilli = millis(); + if (currentMilli - previousMilli2 >= interval) { + previousMilli2 = currentMilli; + if (fade_flag2 == true) { + LED_state2 += increment; + if (LED_state2 == limit) { + fade_flag2 = false; + } + } + if (fade_flag2 == false) { + LED_state2 -= increment; + if (LED_state2 == 0) { + fade_flag2 = true; + ledID = 0; + } + } + } + analogWrite(LED, LED_state2); +} +void green_fade(const long interval, int LED, int limit, int increment) { + currentMilli = millis(); + if (currentMilli - previousMilli3 >= interval) { + previousMilli3 = currentMilli; + if (fade_flag3 == true) { + LED_state3 += increment; + if (LED_state3 == limit) { + fade_flag3 = false; + } + } + if (fade_flag3 == false) { + LED_state3 -= increment; + if (LED_state3 == 0) { + fade_flag3 = true; + ledID++; + } + } + } + analogWrite(LED, LED_state3); +} diff --git a/gesturedemoCW01/SETUP.ino b/gesturedemoCW01/SETUP.ino new file mode 100644 index 0000000..ebd5c3b --- /dev/null +++ b/gesturedemoCW01/SETUP.ino @@ -0,0 +1,53 @@ +void setup_program(void) { + + // Set the I2C Pins for CW01 +#ifdef ESP8266 + Wire.pins(2, 14); + Wire.setClockStretchLimit(15000); + Wire.begin(); +#else + // Start the I2C Comunication + Wire.begin(); +#endif + + // disable wifi + WiFi.forceSleepBegin(); + + // set and start i2c bus + Wire.begin(2, 14); + + // start sensor + apds.setProximityGain(PGAIN_1X); + apds.enableProximitySensor(false); + apds.setProximityIntLowThreshold(4); + OC01.begin(); + + + // start oled + OLED.begin(); + + // clear oled + OD01.clear(); + + // set output leds + pinMode(CW01_RED, OUTPUT); + pinMode(CW01_GREEN, OUTPUT); + pinMode(CW01_BLUE, OUTPUT); + + // turn rgb on + digitalWrite(CW01_RED, HIGH); + digitalWrite(CW01_GREEN, HIGH); + digitalWrite(CW01_BLUE, HIGH); + + delay(2000); + + // turn rgb off + digitalWrite(CW01_RED, LOW); + digitalWrite(CW01_GREEN, LOW); + digitalWrite(CW01_BLUE, LOW); + + delay(1000); + t.tick_main = millis(); + t.tick_poll = millis(); +} + diff --git a/gesturedemoCW01/TASKS.ino b/gesturedemoCW01/TASKS.ino new file mode 100644 index 0000000..a2aa6f7 --- /dev/null +++ b/gesturedemoCW01/TASKS.ino @@ -0,0 +1,20 @@ +void TaskScheduler(void) { + if (ledID == 0) { + red_fade(30, CW01_RED, 255, 5); + } else if (ledID == 1) { + green_fade(30, CW01_GREEN, 255, 5); + } else if (ledID == 2) { + blue_fade(30, CW01_BLUE, 255, 5); + } + + if ((millis() - t.tick_main) > 1000) { + OD01.clear(); + main_code(); + t.tick_main = millis(); + } + if ((millis() - t.tick_poll) > 30) { + // poll sensor + + t.tick_poll = millis(); + } +} diff --git a/gesturedemoCW01/TIMER_CTRL.h b/gesturedemoCW01/TIMER_CTRL.h new file mode 100644 index 0000000..c54afa9 --- /dev/null +++ b/gesturedemoCW01/TIMER_CTRL.h @@ -0,0 +1,10 @@ +#ifndef timer_h +#define timer_h + +struct TIMER_CTRL { + unsigned long tick_main; + unsigned long tick_poll; +}t; + +#endif + diff --git a/gesturedemoCW01/gesturedemoCW01.ino b/gesturedemoCW01/gesturedemoCW01.ino new file mode 100644 index 0000000..3407baf --- /dev/null +++ b/gesturedemoCW01/gesturedemoCW01.ino @@ -0,0 +1,38 @@ +#include + +#include + +#include +#include +#include +#include "TIMER_CTRL.h" +#include +#include + +xOC01 OC01; + +SparkFun_APDS9960 apds = SparkFun_APDS9960(); +uint8_t proximity_data = 0; + +unsigned long currentMilli = 0; +int ledID = 0; +bool fade_flag1 =true; +unsigned long previousMilli1 = 0; // timing variable for LEDS +int LED_state1 = 0; +bool fade_flag2 = true; +unsigned long previousMilli2 = 0; // timing variable for LEDS +int LED_state2 = 0; +bool fade_flag3 = true; +unsigned long previousMilli3 = 0; // timing variable for LEDS +int LED_state3 = 0; + + +void setup() { + // put your setup code here, to run once: + setup_program(); +} + +void loop() { + // put your main code here, to run repeatedly: + main_program(); +}