Alex Glow
Published

Portable Thundercloud

Turn your hotel room pillow into a cloud-shaped lamp—or even a gentle, light-based wake-up alarm.

BeginnerWork in progress2 hours1,737
Portable Thundercloud

Things used in this project

Hardware components

Adafruit Feather HUZZAH with ESP8266 WiFi
Adafruit Feather HUZZAH with ESP8266 WiFi
×1
NeoPixel strip
NeoPixel strip
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×2
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1

Story

Read more

Schematics

Breadboard hookup

Code

lightning.ino

C/C++
Adapted from the "simple" example for NeoPixels :)
// Modified from Adafruit's "simple" example NeoPixel sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            15

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      25

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 100; // delay between pixels
int fade = 0;
int fadeAmount = 20;

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {
  Flash(0);
  Flash(1);
  Flash(2);
  Flash(3);
  Flash(4);
}

void Flash(int bolt) {

  int pixone = bolt * 5;

  for(fade=255; fade>=0; fade = fade - fadeAmount) {
    
  for(int i=pixone;i<(pixone+5);i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(fade/2,fade/3,fade)); // bluish-white

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).

  }

}
  
}

alarm-WIP

C/C++
Mashing together my lightning-cloud code and the code from Adafruit's ESP8266 robot example.
// See also: https://learn.adafruit.com/build-an-esp8266-mobile-robot/configuring-the-robot

// Import required libraries
#include "ESP8266WiFi.h"
#include <aREST.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            15
#define NUMPIXELS      25
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 80; // delay between pixels
int fade = 0;
int fadeAmount = 20;

long previousMillis = 0;
long interval = 8000000;           // interval at which to blink (milliseconds)

// Create aREST instance
aREST rest = aREST();

// WiFi parameters
const char* ssid = "Library of Alexandra";
const char* password = "fiat-hax";

// The port to listen for incoming TCP connections 
#define LISTEN_PORT           80

// Create an instance of the server
WiFiServer server(LISTEN_PORT);

// Function
int now(String message);
int ten(String message);
int twenty(String message);
int cycle(String message);
int night(String message);

void setup(void)
{  
  pixels.begin(); // This initializes the NeoPixel library.
  
  // Start Serial
  Serial.begin(115200);

  // Functions          
  rest.function("now", now);
  rest.function("ten", ten);
  rest.function("twenty", twenty);
  rest.function("cycle", cycle);
  rest.function("night", night);
      
  // Give name and ID to device
  rest.set_id("1");
  rest.set_name("robot");
  
  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
  
  // Print the IP address
  Serial.println(WiFi.localIP());
  
}

void loop() {

  unsigned long currentMillis = millis();
  
  // Handle REST calls
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  while(!client.available()){
    delay(1);
  }
  rest.handle(client);

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;
    Alarm();
    
  }
 
}

int now(String command) {
  Alarm();
}

int ten(String command) {
  interval = 600000;
}

int twenty(String command) {
  interval = 1200000;
}

int cycle(String command) {
  interval = 5400000;
}

int night(String command) {
  interval = 28800000;
}


void Flash(int bolt) {

  int pixone = bolt * 5;

// Quick double-tap of bright flashes, fading gradually down to dim lighting.
  for(fade=150; fade>=90; fade = fade - fadeAmount) {

  for(int i=pixone;i<(pixone+5);i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(fade/2,fade/3,fade)); // bluish-white

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(10); // Delay for a short period of time (in milliseconds).

  }
  }

  for(fade=255; fade>=0; fade = fade - fadeAmount) {

  for(int i=pixone;i<(pixone+5);i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(fade/2,fade/3,fade)); // bluish-white

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).

  }
}
}


void Alarm() {
  Flash(0);
  Flash(1);
  Flash(2);
  Flash(3);
  Flash(4);
}

Credits

Alex Glow

Alex Glow

145 projects • 1571 followers
The Hackster team's resident Hardware Nerd. I love robots, music, EEG, wearables, and languages. FIRST Robotics kid.

Comments