For the Unusual switch I decided to continue the concepts I was exploring within the first seven weeks of interactive and generative art using p5.js. I call this switch the “Handcuff” switch. A general rule of thumb tells you “gif > any other file format” so here is my demonstration whilst also trying to re-enact how the person wearing the handcuffs would feel
const int switchPin = 2;
const int ledPin = 13;
bool handcuffsLocked = false; // tracks if handcuffs are on or off
void setup() {
pinMode(switchPin, INPUT_PULLUP); // Internal pull-up resistor
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState == LOW && !handcuffsLocked) {
handcuffsLocked = true; // lock the handcuffs
digitalWrite(ledPin, HIGH);
Serial.println("Handcuffs ON");
}
if (switchState == HIGH && handcuffsLocked) {
handcuffsLocked = false; // unlock the handcuffs
digitalWrite(ledPin, LOW);
Serial.println("Handcuffs OFF");
}
delay(100);
}
const int switchPin = 2;
const int ledPin = 13;
bool handcuffsLocked = false; // tracks if handcuffs are on or off
void setup() {
pinMode(switchPin, INPUT_PULLUP); // Internal pull-up resistor
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState == LOW && !handcuffsLocked) {
handcuffsLocked = true; // lock the handcuffs
digitalWrite(ledPin, HIGH);
Serial.println("Handcuffs ON");
}
if (switchState == HIGH && handcuffsLocked) {
handcuffsLocked = false; // unlock the handcuffs
digitalWrite(ledPin, LOW);
Serial.println("Handcuffs OFF");
}
delay(100);
}
const int switchPin = 2; const int ledPin = 13; bool handcuffsLocked = false; // tracks if handcuffs are on or off void setup() { pinMode(switchPin, INPUT_PULLUP); // Internal pull-up resistor pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { int switchState = digitalRead(switchPin); if (switchState == LOW && !handcuffsLocked) { handcuffsLocked = true; // lock the handcuffs digitalWrite(ledPin, HIGH); Serial.println("Handcuffs ON"); } if (switchState == HIGH && handcuffsLocked) { handcuffsLocked = false; // unlock the handcuffs digitalWrite(ledPin, LOW); Serial.println("Handcuffs OFF"); } delay(100); }
I designed this basic code to detect and track when the handcuffs are unlocked. Mainly, it is a conditional that keeps track of the states (on) or (off).