Gabriel Arnold-Jecker
Published

Touch-Light Lantern

Touch-Light has two different functions; a button that controls the brightness of pixels and a sensor that controls the hue lights and WEMO.

IntermediateFull instructions providedOver 2 days27
Touch-Light Lantern

Things used in this project

Hardware components

NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
water sensor
×1
SparkFun RedBot Sensor - Wheel Encoder
SparkFun RedBot Sensor - Wheel Encoder
×1

Story

Read more

Custom parts and enclosures

button knob

I 3D printed a button knob that controls the pixels when the encoder is moved

Schematics

Project_Light_lantern

fritzing diagram for my midterm project

Code

Project_Light_lantern

C/C++
the code is for a device that the argon is hooked up to called the Touch-Light Lantern. it has two separate functions one of them doesn't require any internet while the other one does. The first one is a button I've attached to my encoder so that whenever you turn the dial a certain direction it turns on the pixels and then adjusts the brightness to the setting you like. The 2nd function (which requires the internet) is a heat sensor attached to the outside of the lantern that's designed to turn on the lights in the room to
/*
 * Project Project_Light_Lantern
 * Description:
 * Author:
 * Date:
 */
#include "Adafruit_SSD1306.h"
#include "Adafruit_GFX.h"
#include "IoTClassroom_CNM.h"
#include <Encoder.h>
#include "colors.h"
#include "neopixel.h"
#include "Light_Bulb.h"
int PINA=D11;
int PINB=D12;
const int PIXELPIN=D5;
const int PIXELNUMBER=16;
int pixelBrightness;
int maxPos=15;
int startPixel=0;
int endPixel=15;
int color1=green;
int color2=blue;
int positionA;
int pixelCount;
const int OLED_RESET=4;
bool buttonState;
int buttonPin=A3;
const int MYWEMO1=1;
const int MYWEMO2=2;

Adafruit_SSD1306 display(OLED_RESET);
Adafruit_NeoPixel pixel(PIXELNUMBER,PIXELPIN,WS2812B);
Encoder myEnc(PINA, PINB);
SYSTEM_MODE(MANUAL);
int BULB;
int colorHue;
int brightness;
int val;
const int Tswitch=A3;
// setup() runs once, when the device is first turned on.
void setup() {
  Serial.begin(9600);
  waitFor(Serial.isConnected,15000);
  display.begin (SSD1306_SWITCHCAPVCC, 0x3c);
  display.display();
  delay(200);
  display.clearDisplay();
  display.drawBitmap(16,20, myBitmap,112, 44, 1);
  display.display();
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
  display.setTextSize(1);
  display.setTextColor(BLACK,WHITE);
  display.printf("Light It Up%c",33);
  display.display();

  pinMode(Tswitch, INPUT);
  pixel.begin();
  pixel.show();


  WiFi.on();
  WiFi.setCredentials("IoTNetwork");
   WiFi.connect();
  while(WiFi.connecting()) {
    Serial.printf(".");
  }
  Serial.printf("\n\n");

}
  // Put initialization like pinMode and begin functions here.



// loop() runs over and over again, as quickly as it can execute.
void loop() {
   buttonState=digitalRead(buttonPin);
 positionA=myEnc.read();
if(positionA>95){
  positionA=95;
  myEnc.write(95);
}
if(positionA<0){
  positionA=0;
  myEnc.write(0);
}

 pixelBrightness=map(positionA,0,95,0,229);
 pixel.setBrightness(pixelBrightness);
 pixelFill(startPixel,endPixel,color1,color2);
// Serial.printf("val of my encoder/n");
 Serial.printf("%i %i\n",positionA,pixelBrightness);
  
    Serial.printf("%i,%i\n",positionA,pixelBrightness);
    val=analogRead(Tswitch);
    brightness=255;
    // Serial.printf("val=%i\n",val);
    if (val<200){
     for (BULB=1; BULB<=3; BULB++){
      setHue(BULB,false,HueGreen,0,255);
      switchOFF(MYWEMO1);

     } 
    //  Serial.printf("bulb off");
     for (BULB=4; BULB<=6; BULB++){
      setHue(BULB, false, HueBlue,0,255);
      switchOFF(MYWEMO2);
     }
    }
    
    else{
      for (BULB=1; BULB<=3; BULB++){
        setHue(BULB,true,HueGreen,brightness,255);
        Serial.printf("bulb on");
        switchON(MYWEMO1);
      }
        for (BULB=4; BULB<=6; BULB++){
          setHue(BULB, true, HueBlue,brightness,255);
          switchON(MYWEMO2);
 
}
}
}
void pixelFill(int startPixel,int endPixel,int color1,int color2){
    for (pixelCount=startPixel; pixelCount<=endPixel; pixelCount=pixelCount+2){
      pixel.setPixelColor(pixelCount,color1);
      pixel.setPixelColor(pixelCount+1,color2);
      pixel.show();  
    }
}

     

Project_Light_lantern

C/C++
the code is for a device that the argon is hooked up to called the Touch-Light Lantern. it has two separate functions one of them doesn't require any internet while the other one does. The first one is a button I've attached to my encoder so that whenever you turn the dial a certain direction it turns on the pixels and then adjusts the brightness to the setting you like. The 2nd function (which requires the internet) is a heat sensor attached to the outside of the lantern that's designed to turn on the lights in the room to
/*
 * Project Project_Light_Lantern
 * Description:
 * Author:
 * Date:
 */
#include "Adafruit_SSD1306.h"
#include "Adafruit_GFX.h"
#include "IoTClassroom_CNM.h"
#include <Encoder.h>
#include "colors.h"
#include "neopixel.h"
#include "Light_Bulb.h"
int PINA=D11;
int PINB=D12;
const int PIXELPIN=D5;
const int PIXELNUMBER=16;
int pixelBrightness;
int maxPos=15;
int startPixel=0;
int endPixel=15;
int color1=green;
int color2=blue;
int positionA;
int pixelCount;
const int OLED_RESET=4;
bool buttonState;
int buttonPin=A3;
const int MYWEMO1=1;
const int MYWEMO2=2;

Adafruit_SSD1306 display(OLED_RESET);
Adafruit_NeoPixel pixel(PIXELNUMBER,PIXELPIN,WS2812B);
Encoder myEnc(PINA, PINB);
SYSTEM_MODE(MANUAL);
int BULB;
int colorHue;
int brightness;
int val;
const int Tswitch=A3;
// setup() runs once, when the device is first turned on.
void setup() {
  Serial.begin(9600);
  waitFor(Serial.isConnected,15000);
  display.begin (SSD1306_SWITCHCAPVCC, 0x3c);
  display.display();
  delay(200);
  display.clearDisplay();
  display.drawBitmap(16,20, myBitmap,112, 44, 1);
  display.display();
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
  display.setTextSize(1);
  display.setTextColor(BLACK,WHITE);
  display.printf("Light It Up%c",33);
  display.display();

  pinMode(Tswitch, INPUT);
  pixel.begin();
  pixel.show();


  WiFi.on();
  WiFi.setCredentials("IoTNetwork");
   WiFi.connect();
  while(WiFi.connecting()) {
    Serial.printf(".");
  }
  Serial.printf("\n\n");

}

void loop() {
   buttonState=digitalRead(buttonPin);
 positionA=myEnc.read();
if(positionA>95){
  positionA=95;
  myEnc.write(95);
}
if(positionA<0){
  positionA=0;
  myEnc.write(0);
}

 pixelBrightness=map(positionA,0,95,0,229);
 pixel.setBrightness(pixelBrightness);
 pixelFill(startPixel,endPixel,color1,color2);
// Serial.printf("val of my encoder/n");
 Serial.printf("%i %i\n",positionA,pixelBrightness);
  
    Serial.printf("%i,%i\n",positionA,pixelBrightness);
    val=analogRead(Tswitch);
    brightness=255;
    if (val<200){
     for (BULB=1; BULB<=3; BULB++){
      setHue(BULB,false,HueGreen,0,255);
      switchOFF(MYWEMO1);
     } 
     for (BULB=4; BULB<=6; BULB++){
      setHue(BULB, false, HueBlue,0,255);
      switchOFF(MYWEMO2);
     }
    }
    
    else{
      for (BULB=1; BULB<=3; BULB++){
        setHue(BULB,true,HueGreen,brightness,255);
        Serial.printf("bulb on");
        switchON(MYWEMO1);
      }
        for (BULB=4; BULB<=6; BULB++){
          setHue(BULB, true, HueBlue,brightness,255);
          switchON(MYWEMO2);
 
}
}
}
void pixelFill(int startPixel,int endPixel,int color1,int color2){
    for (pixelCount=startPixel; pixelCount<=endPixel; pixelCount=pixelCount+2){
      pixel.setPixelColor(pixelCount,color1);
      pixel.setPixelColor(pixelCount+1,color2);
      pixel.show();  
    }
}

     

Credits

Gabriel Arnold-Jecker

Gabriel Arnold-Jecker

0 projects • 1 follower
I am currently learning C++ still new to developing but I can't wait to start developing my own codes.

Comments

Add projectSign up / Login