Skip to content

Commit

Permalink
Source added
Browse files Browse the repository at this point in the history
  • Loading branch information
brittanybull committed Jul 23, 2018
1 parent da290d7 commit f168ff8
Show file tree
Hide file tree
Showing 14 changed files with 475 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gesturedemoCC03_CS11/LOOP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void main_program(void) {
while (1) {
delay(0);
TaskScheduler();
}
}

37 changes: 37 additions & 0 deletions gesturedemoCC03_CS11/MAIN.ino
Original file line number Diff line number Diff line change
@@ -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);
}

60 changes: 60 additions & 0 deletions gesturedemoCC03_CS11/RGB.ino
Original file line number Diff line number Diff line change
@@ -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);
}
53 changes: 53 additions & 0 deletions gesturedemoCC03_CS11/SETUP.ino
Original file line number Diff line number Diff line change
@@ -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();
}

20 changes: 20 additions & 0 deletions gesturedemoCC03_CS11/TASKS.ino
Original file line number Diff line number Diff line change
@@ -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();
}
}
10 changes: 10 additions & 0 deletions gesturedemoCC03_CS11/TIMER_CTRL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef timer_h
#define timer_h

struct TIMER_CTRL {
unsigned long tick_main;
unsigned long tick_poll;
}t;

#endif

63 changes: 63 additions & 0 deletions gesturedemoCC03_CS11/gesturedemoCC03_CS11.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <SparkFun_APDS9960.h>

#include <xOC01.h>

#include <xCore.h>
#include <xOD01.h>
#include "TIMER_CTRL.h"
#include <SparkFun_APDS9960.h>
#include <xOC01.h>

#if defined(ESP8266)
#define RED RED
#define GREEN GREEN
#define BLUE BLUE
#include <ESP8266WiFi.h>
#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();
}
7 changes: 7 additions & 0 deletions gesturedemoCW01/LOOP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
void main_program(void) {
while (1) {
delay(0);
TaskScheduler();
}
}

37 changes: 37 additions & 0 deletions gesturedemoCW01/MAIN.ino
Original file line number Diff line number Diff line change
@@ -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);
}

60 changes: 60 additions & 0 deletions gesturedemoCW01/RGB.ino
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit f168ff8

Please sign in to comment.