Don
Published

Smart lamp

Multi-functional, solar powered streetlight designed to fashionably improve visibility as well as offer generic information via IoT

IntermediateWork in progress559
Smart lamp

Things used in this project

Hardware components

Arduino Nano 33 IoT
Arduino Nano 33 IoT
×1
WS2812 Addressable LED Strip
Digilent WS2812 Addressable LED Strip
×1
Real Time Clock (RTC)
Real Time Clock (RTC)
×1

Software apps and online services

LightBlue Explorer
Punch Through LightBlue Explorer

Story

Read more

Schematics

circuit_0dMPaS1jLG.svg

Code

timer for lamp

C/C++
These are two example sketches fused together (RST for realtime and a simple adafruit code for ws2812). I'm obviously not well versed when it comes to coding, so I welcome any advice apart from a solution to the problem I have with integrating the ArduinoBLE library in the code.
// http://quadpoint.org/projects/arduino-ds1302
#include <stdio.h>
#include <DS1302.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

#define PIN_FOR_1        3
#define PIN_FOR_2        2

#define NUMPIXELS1 2
#define NUMPIXELS2 3

Adafruit_NeoPixel pixels1(NUMPIXELS1, PIN_FOR_1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS2, PIN_FOR_2, NEO_GRB + NEO_KHZ800);

#define DELAYVAL 10

namespace {

//   http://datasheets.maximintegrated.com/en/ds/DS1302.pdf

const int kCePin   = 4;  // Chip Enable
const int kIoPin   = 5;  // Input/Output
const int kSclkPin = 6;  // Serial Clock
int hr = hr;
// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);

/*String dayAsString(const Time::Day day) {
  switch (day) {
    case Time::kSunday: return "Sunday";
    case Time::kMonday: return "Monday";
    case Time::kTuesday: return "Tuesday";
    case Time::kWednesday: return "Wednesday";
    case Time::kThursday: return "Thursday";
    case Time::kFriday: return "Friday";
    case Time::kSaturday: return "Saturday";
  }
  return "(unknown day)";
}*/


void zetLampAan(bool aan){
if(aan){
  
  pixels1.begin();
  pixels2.begin();

  for(int i=0; i<12; i++) {

    pixels1.setPixelColor(i, pixels1.Color(155, 155, 155));
    pixels2.setPixelColor(i, pixels1.Color(0, 155, 0));
    pixels1.show();
    pixels2.show();

    delay(100);
    }
  }

  if(!aan){
    pixels1.begin();
    pixels2.begin();

    for(int i=0; i<12; i++) {

    pixels1.setPixelColor(i, pixels1.Color(0, 0, 0));
    pixels2.setPixelColor(i, pixels2.Color(0, 0, 0));
    pixels1.show();
    pixels2.show();
    }
  }
}

void printTime() {

  Time t = rtc.time();

  int hrInt = t.hr;

  if(hrInt>=4 && hrInt<19){zetLampAan(0);}
  else{zetLampAan(1);};
  Serial.print('\n');
  Serial.print(hrInt);
  }

}  // namespace

void setup() {
  Serial.begin(9600);
  pixels1.begin();
  pixels2.begin();
  rtc.writeProtect(true);
  rtc.halt(false);

  // Make a new time object to set the date and time.
  // Sunday, September 22, 2013 at 01:38:50.
  /*Time t(2020, 12, 17, 20, 17, 30, Time::kThursday);

  // Set the time and date on the chip.
  rtc.time(t);*/
}

void loop() {
  printTime();
  delay(1000);
  //pixels1.clear();pixels2.clear();
  
  
  
}

Credits

Don
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.