Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wemos committed Apr 16, 2016
2 parents 24ecaa6 + 032628e commit c550f92
Show file tree
Hide file tree
Showing 31 changed files with 1,738 additions and 68 deletions.
10 changes: 5 additions & 5 deletions 01.Basics/Fade/Fade.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

const int ledPin = BUILTIN_LED; // the onboard LED
int brightness = 0; // how bright the LED is (0 = off, 128 = dim, 255 = full)
int brightness = 0; // how bright the LED is (0 = full, 512 = dim, 1023 = off)
int fadeAmount = 5; // how many points to fade the LED by
const int delayMillis = 30; // how long to pause between each loop
const int delayMillis = 10; // how long to pause between each loop

void setup() {
pinMode(ledPin, OUTPUT); // initialize onboard LED as output
Expand All @@ -19,12 +19,12 @@ void loop() {
// increment/decrement the brightness for the next loop
brightness = brightness + fadeAmount;

// limit to 8-bit (0-255)
// limit to 10-bit (0-1023)
if (brightness < 0) brightness = 0;
if (brightness > 255) brightness = 255;
if (brightness > 1023) brightness = 1023;

// reverse the direction of the fading at each end
if (brightness == 0 || brightness == 255) {
if (brightness == 0 || brightness == 1023) {
fadeAmount = -fadeAmount;
}

Expand Down
41 changes: 41 additions & 0 deletions 02.Special/DeepSleep/Blink/Blink.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Deep Sleep - Blink
*
* Blinks the onboard LED, sleeps for 10 seconds and repeats
*
* Connections:
* D0 -- RST
*
* If you cant reprogram as the ESP is sleeping, disconnect D0 - RST and try again
*/

// sleep for this many seconds
const int sleepSeconds = 5;

void setup() {
Serial.begin(9600);
Serial.println("\n\nWake up");

pinMode(BUILTIN_LED, OUTPUT);

// Connect D0 to RST to wake up
pinMode(D0, WAKEUP_PULLUP);

// LED: LOW = on, HIGH = off
Serial.println("Start blinking");
for (int i = 0; i < 20; i++)
{
digitalWrite(BUILTIN_LED, LOW);
delay(100);
digitalWrite(BUILTIN_LED, HIGH);
delay(100);
}
Serial.println("Stop blinking");

Serial.printf("Sleep for %d seconds\n\n", sleepSeconds);

// convert to microseconds
ESP.deepSleep(sleepSeconds * 1000000);
}

void loop() {
}
57 changes: 57 additions & 0 deletions 04.Shields/DHT_Shield/DeepSleep/DeepSleep.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* DHT Shield - Deep Sleep
*
* Displays humidity, temperature and heat index, sleeps for 10 seconds and repeats
*
* Connections:
* D0 -- RST
*
* If you cant reprogram as the ESP is sleeping, disconnect D0 - RST and try again
*
* Depends on Adafruit DHT Arduino library
* https://github.com/adafruit/DHT-sensor-library
*/

#include "DHT.h"
#define DHTPIN D4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// sleep for this many seconds
const int sleepSeconds = 10;

float humidity, temperature, heatIndex;
char str_humidity[10], str_temperature[10], str_heatIndex[10];

void setup() {
Serial.begin(9600);
Serial.println("\n\nWake up");

// Connect D0 to RST to wake up
pinMode(D0, WAKEUP_PULLUP);

Serial.println("Initialize DHT sensor");
dht.begin();
delay(2000);

Serial.println("Read DHT sensor");
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
}
float heatIndex = dht.computeHeatIndex(temperature, humidity, false);

// Convert the floats to strings and round to 2 decimal places
dtostrf(humidity, 1, 2, str_humidity);
dtostrf(temperature, 1, 2, str_temperature);
dtostrf(heatIndex, 1, 2, str_heatIndex);

Serial.printf("Humidity: %s %%\nTemperature: %s *C\nHeat index: %s *C\n", str_humidity, str_temperature, str_heatIndex);
Serial.printf("Sleep for %d seconds\n\n", sleepSeconds);

// convert to microseconds
ESP.deepSleep(sleepSeconds * 1000000);
}

void loop() {
}
207 changes: 207 additions & 0 deletions 05.Displays/NeoPixel-Stick/examples/examples.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/* NeoPixel Stick - Examples
* Adafruit NeoPixel Stick consists of 8x 5050 RGB WS2812B LEDs
* http://adafruit.com/products/1426
*
* Connections:
* D2 --- DIN
* 3V3 -- 5VDC
* G ---- GND (either)
*
* Adafruit recommendations:
* - add a 1000uF capacitor across the power lines 5VDC and GND.
* - add a 300-500 Ohm resistor on first pixel's data input DIN.
* - avoid connecting on a live circuit... if you must, connect GND first.
*
* Dependencies:
* https://github.com/adafruit/Adafruit_NeoPixel
*/

#include <Adafruit_NeoPixel.h>

// NeoPixel stick DIN pin
#define DIN_PIN D2

// How many NeoPixels on the stick?
#define NUM_PIXELS 8

// Third parameter:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream (NeoPixel Stick)
// NEO_KHZ400 400 KHz bitstream for FLORA pixels
// NEO_KHZ800 800 KHz bitstream for High Density LED strip (NeoPixel Stick)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, DIN_PIN, NEO_GRB + NEO_KHZ800);

int pause = 1000;

void setup() {
Serial.begin(9600);
strip.begin();
strip.show(); // Start with all pixels off
delay(pause);
}

void loop() {
Serial.println("Color Wipe Red");
colorWipe(strip.Color(255, 0, 0), 50);
delay(pause);

Serial.println("Color Wipe Green");
colorWipe(strip.Color(0, 255, 0), 50);
delay(pause);

Serial.println("Color Wipe Blue");
colorWipe(strip.Color(0, 0, 255), 50);
delay(pause);

Serial.println("Color Wipe White");
colorWipe(strip.Color(255, 255, 255), 50);
delay(pause);

Serial.println("Color Wipe Cyan");
colorWipe(strip.Color(0, 255, 255), 50);
delay(pause);

Serial.println("Color Wipe Magenta");
colorWipe(strip.Color(255, 0, 255), 50);
delay(pause);

Serial.println("Color Wipe Yellow");
colorWipe(strip.Color(255, 255, 0), 50);
delay(pause);

Serial.println("Color Wipe Black");
colorWipe(strip.Color(0, 0, 0), 50);
delay(pause);

Serial.println("Theater Chase Red");
theaterChase(strip.Color(127, 0, 0), 50);
delay(pause);

Serial.println("Theater Chase Green");
theaterChase(strip.Color(0, 127, 0), 50);
delay(pause);

Serial.println("Theater Chase Blue");
theaterChase(strip.Color(0, 0, 127), 50);
delay(pause);

Serial.println("Theater Chase White");
theaterChase(strip.Color(127, 127, 127), 50);
delay(pause);

Serial.println("Random Colors");
randomColors(100);
delay(pause);

Serial.println("Rainbow");
rainbow(20);
delay(pause);

Serial.println("Rainbow Cycle");
rainbowCycle(20);
delay(pause);

Serial.println("Theater Chase Rainbow");
theaterChaseRainbow(50);
delay(pause);
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
uint16_t i;
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}

void rainbow(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}

void randomColors(uint8_t wait) {
uint16_t i, j;
for(j=0; j<50; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(random(0,255), random(0,255), random(0,255)));
}
strip.show();
delay(wait);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
uint16_t j, q, i;
for (j=0; j<10; j++) { //do 10 cycles of chasing
for (q=0; q < 3; q++) {
for (i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();

delay(wait);

for (i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
uint16_t j, q, i;
for (j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (q=0; q < 3; q++) {
for (i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();

delay(wait);

for (i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

Loading

0 comments on commit c550f92

Please sign in to comment.