Created
December 19, 2015 11:50
-
-
Save anonymous/7dc4d9a96a28e74dfe1a to your computer and use it in GitHub Desktop.
A sex toy cabinet that chooses toys for you
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include "FastLED.h" | |
#define PIX_PER_SHELF 43 //number of LEDs you have on each shelf | |
#define SHELVES 6 // number of shelves you have | |
#define DATA_PIN 6 // neopixel signal pin | |
#define DOOR_SWITCH 7 // magnet and reed switch on cupboard door | |
#define AMBIENT_TIME 1800000 // milliseconds to leave cabinet in ambient lighting mode (1,800,000 = 30 minutes) | |
int toys[] = {5,4,4,4,8,8}; // how many toys you have on each row | |
/* No need to adjust anything below here */ | |
// used to make basic mood lamp colour fading feature | |
int fade_h; | |
int fade_direction = 1; | |
bool opened = false; | |
bool ambient_mode = false; | |
bool chosen = false; | |
int direction = -10; | |
unsigned long timer; // used to count the time | |
// Define the array of leds | |
CRGB leds[PIX_PER_SHELF*SHELVES]; | |
void setup() { | |
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, PIX_PER_SHELF*SHELVES); | |
pinMode(DOOR_SWITCH,INPUT); | |
Serial.begin(115200); | |
FastLED.show(); // Initialize all pixels to 'off' | |
randomSeed(analogRead(0)); | |
resetPixelStates(); | |
} | |
void resetPixelStates(){ | |
for(int i=0;i<(PIX_PER_SHELF*SHELVES);i++){ | |
leds[i] = CHSV( 0, 0, 0); | |
} | |
FastLED.show(); | |
} | |
void loop() { | |
if(digitalRead(DOOR_SWITCH) == 1 && chosen == false){ // no toys picked yet, door opened | |
opened = true; | |
ambient_mode = false; | |
chooseToys(); | |
} | |
else if (digitalRead(DOOR_SWITCH) == 1 && chosen == true){ // we've displaying chosen toys, just wait and | |
//do nothing | |
} | |
else if(ambient_mode == true && opened == false){ | |
if (millis() - timer > AMBIENT_TIME){ | |
// timer expired. reset everything to off state. | |
resetPixelStates(); | |
opened = false; | |
chosen = false; | |
ambient_mode = false; | |
} | |
else{ | |
ambience(); | |
} | |
} | |
else if(opened == true && digitalRead(DOOR_SWITCH) == 0){ // was opened, now closed again | |
opened = false; | |
chosen = false; | |
ambient_mode = true; | |
// switch to ambient lighting mode for 30 minutes, unless reopened again. | |
timer = millis(); | |
ambience(); | |
} | |
else{ | |
resetPixelStates(); | |
} | |
} | |
void ambience(){ | |
//mood mood lamp that cycles through colours | |
for (int i=0;i<PIX_PER_SHELF*SHELVES;i++){ | |
leds[i] = CHSV( fade_h, 255, 255); | |
} | |
if(fade_h >254){ | |
fade_direction = -1; //reverse once we get to 254 | |
} | |
else if(fade_h < 0){ | |
fade_direction = 1; | |
} | |
fade_h += fade_direction; | |
FastLED.show(); | |
delay(100); | |
} | |
void chooseToys(){ | |
if(chosen == false){ | |
resetPixelStates(); | |
for(uint16_t s=0; s<SHELVES; s++){ | |
int chosenToy = random(1,toys[s]+1); | |
Serial.print("shelf number "); | |
Serial.print(s+1); | |
Serial.print(" :chosen "); | |
Serial.print(chosenToy); | |
Serial.print(" of "); | |
Serial.println(toys[s]); | |
float pixelsPerToy = (float)PIX_PER_SHELF/toys[s]; | |
Serial.print("pixels per toy: "); | |
Serial.println(pixelsPerToy); | |
int startPixel = (s*PIX_PER_SHELF); // first pixel of this row | |
int endPixel = startPixel+(PIX_PER_SHELF-1); // last pixel of this row | |
int toyStartPixel = startPixel + (pixelsPerToy*(chosenToy-1)); | |
int toyEndPixel = startPixel + (pixelsPerToy*(chosenToy))-1; | |
Serial.print(toyStartPixel); | |
Serial.print(":"); | |
Serial.println(toyEndPixel); | |
for(int i = toyStartPixel; i <= toyEndPixel; i++){ | |
leds[i] = CHSV( 0, 0, 255); | |
delay(50); | |
FastLED.show(); | |
} | |
} | |
chosen = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment