Joseph Maes
Published

Duck hunt

Have fun checking you room, temperature. Duck rotate when laser its the sensor and light's will tune on or off. And shows temp.

IntermediateShowcase (no instructions)8 hours50
Duck hunt

Things used in this project

Story

Read more

Code

Duck hunt

C/C++
The Duckleks are coming, will you be the one to save us all? Or you can just check the temperature in the room or turn on lights with a laser gun and have a little light show and duck moving back and forth.
#include "Particle.h"
#include "IoTclassroom_CNM.h"
#include <neopixel.h>
#include "color.h"

const int PIXELCOUNT = 45;

int bri = 65;

//const int(A0);

int pix;
int rnd_red;
int rnd_grn;
int rnd_blu;

Adafruit_NeoPixel pixel (PIXELCOUNT,SPI1,WS2812B);

bool OnOff; //use this to toggle between true or false (on or off)
const int BULB=3; 
int color;
float volts;
int val;
const int potPin=A0;
const int MYWEMO=2;

Servo myser;
Button hueButton(D3); //create button object from button class
SYSTEM_MODE(MANUAL);


void setup() {
  myser.attach(D13);
  pixel.begin ();
   pixel.setBrightness (bri);//value is over 225
  pixel.show();
  Serial.begin(9600);
  waitFor(Serial.isConnected,15000);

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

void loop() { 
 rnd_red =random (225);
 rnd_grn =random (225);
 rnd_blu =random (225);

  for (int pix=0;pix<45;pix++){
   pixel.setPixelColor (pix,rnd_red ,rnd_grn ,rnd_blu);
  
  
  pixel.show();

  if (hueButton.isClicked()){
    delay(25);
    OnOff = !OnOff;
     Serial.printf("Setting color of bulb %i to color %06i\n",BULB,HueRainbow[color%7]);
  setHue(BULB,OnOff,HueRainbow[color%7],random(32,255),255);
  color++;
  }

 val = analogRead(potPin);
  volts = (3.3/4095.0) * val;
    Serial.printf("input=%0.1f\n",volts);
  
 if (volts >=2.3){
myser.write(1);
Serial.printf("Turning on Weno# %i\n",MYWEMO);
  wemoWrite(MYWEMO,HIGH);

}else{
  myser.write(0);
  Serial.printf("Turning off Wemo# %i\n",MYWEMO);
  wemoWrite(MYWEMO,LOW);
  }   

}
}

Duck hunt

C/C++
#include "Particle.h"
#include "IoTclassroom_CNM.h"
#include <neopixel.h>
#include "color.h"

const int PIXELCOUNT = 45;

int bri = 65;

//const int(A0);

int pix;
int rnd_red;
int rnd_grn;
int rnd_blu;

Adafruit_NeoPixel pixel (PIXELCOUNT,SPI1,WS2812B);

bool OnOff; //use this to toggle between true or false (on or off)
const int BULB=3; 
int color;
float volts;
int val;
const int potPin=A0;
const int MYWEMO=2;

Servo myser;
Button hueButton(D3); //create button object from button class
SYSTEM_MODE(MANUAL);


void setup() {
  myser.attach(D13);
  pixel.begin ();
   pixel.setBrightness (bri);//value is over 225
  pixel.show();
  Serial.begin(9600);
  waitFor(Serial.isConnected,15000);

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

void loop() { 
 rnd_red =random (225);
 rnd_grn =random (225);
 rnd_blu =random (225);

  for (int pix=0;pix<45;pix++){
   pixel.setPixelColor (pix,rnd_red ,rnd_grn ,rnd_blu);
  
  
  pixel.show();

  if (hueButton.isClicked()){
    delay(25);
    OnOff = !OnOff;
     Serial.printf("Setting color of bulb %i to color %06i\n",BULB,HueRainbow[color%7]);
  setHue(BULB,OnOff,HueRainbow[color%7],random(32,255),255);
  color++;
  }

 val = analogRead(potPin);
  volts = (3.3/4095.0) * val;
    Serial.printf("input=%0.1f\n",volts);
  
 if (volts >=2.3){
myser.write(1);
Serial.printf("Turning on Weno# %i\n",MYWEMO);
  wemoWrite(MYWEMO,HIGH);

}else{
  myser.write(0);
  Serial.printf("Turning off Wemo# %i\n",MYWEMO);
  wemoWrite(MYWEMO,LOW);
  }   

}
}

Credits

Joseph Maes
3 projects • 5 followers

Comments