Hello Axl64,
it's interesting we were both playing with the same arduino setup at the same time
Since I don't want to connect arduino board to the computer every time a play with SB, my project includes time setting using buttons (as Riddle pointed out - but don't know if my setup will suite his needs) and some LED lights to indicate time length.
There are 6 LED lights, 3 red and 3 yellow. Red lights indicate hours (0, 1, 2, 3) and yellow LEDs show quarters of hour (0, 15, 30, 45).
So you can set any time between 0h:0m up to 3h:45m. Since my SB sessions are usually hour or two long, this time frame fills my needs.
This project is still under testing (about 20 runs so far and no failure), so I don't have any box or package for it.
Here is the code itself:
Code: Select all
#include <Servo.h>
boolean sessionStarted = false;
int hours = 0;
int MAX_HOURS = 3;
int HOURS_START_PIN = 5;
int minutes = 0;
int MAX_MINUTES = 3;
int MINUTES_START_PIN = 2;
boolean readingHoursInProgress = false;
boolean readingMinutesInProgress = false;
boolean readingSessionBtnInProgress = false;
unsigned long endTime = 0;
unsigned long MINUTES_MULTIPLIER = 60000; // 1000 for seconds, 60000 for minutes
unsigned long HOURS_MULTIPLIER = MINUTES_MULTIPLIER * 60;
Servo servo;
void setup() {
// put your setup code here, to run once:
for (int pin = 2; pin <= 7; pin++) {
pinMode(pin, OUTPUT);
}
// SERVO
servo.attach(9);
servo.write(0);
delay(250);
}
void loop() {
if (!sessionStarted) {
readMinutes();
readHours();
showCurrentTime();
} else {
if (millis() > endTime) {
finishSession();
}
}
if (sessionStatusChanged()) {
if (!sessionStarted) {
startSession();
} else {
finishSession();
}
}
}
void finishSession() {
sessionStarted = false;
servo.write(170);
fleshLED();
servo.write(0);
}
void startSession() {
fleshLED();
sessionStarted = true;
endTime = minutes * 15 * MINUTES_MULTIPLIER;
endTime += hours * HOURS_MULTIPLIER;
endTime += millis();
}
void fleshLED() {
for (int i = 0; i < 5; i++) {
for (int pin = 2; pin <= 7; pin++) {
digitalWrite(pin, HIGH);
}
delay(500);
for (int pin = 2; pin <= 7; pin++) {
digitalWrite(pin, LOW);
}
delay(500);
}
}
boolean sessionStatusChanged() {
int sessionBtnInput = analogRead(A2);
if (!readingSessionBtnInProgress) {
if (sessionBtnInput > 1000) {
readingSessionBtnInProgress = true;
}
} else {
if (sessionBtnInput == 0) {
readingSessionBtnInProgress = false;
// react only after user releases button (can be implemented everywhere)
return true;
}
}
return false;
}
void readMinutes() {
int minInput = analogRead(A0);
if (!readingMinutesInProgress) {
if (minInput > 1000) {
minutes++;
if (minutes > MAX_MINUTES) {
minutes = 0;
}
readingMinutesInProgress = true;
}
} else {
if (minInput == 0) {
readingMinutesInProgress = false;
}
}
}
void readHours() {
int hrsInput = analogRead(A1);
if (!readingHoursInProgress) {
if (hrsInput > 1000) {
hours++;
if (hours > MAX_HOURS) {
hours = 0;
}
readingHoursInProgress = true;
}
} else {
if (hrsInput == 0) {
readingHoursInProgress = false;
}
}
}
void showCurrentTime() {
// show minutes
for (int pin = MINUTES_START_PIN; pin < MINUTES_START_PIN + MAX_MINUTES; pin++) {
digitalWrite(pin, pin < MINUTES_START_PIN + minutes ? HIGH : LOW);
}
// show hours
for (int pin = HOURS_START_PIN; pin < HOURS_START_PIN + MAX_HOURS; pin++) {
digitalWrite(pin, pin < HOURS_START_PIN + hours ? HIGH : LOW);
}
}
LED examples:
Board photos:
Please feel free to comment anything you don't like about this setup.
Happy bondage!!!