My stupid pet trick started at the junk shelf, where I happened to find an old Zip drive, I liked the idea of having a clean translucent case to hide my dirty electronic circuitry crafting skills. I knew I wanted it to have one obvious control and others which are hidden and discrete, that effect the behavior of the device in an unapparent manner. Since me little case had one button, a door and a USB port, I figured, why not use these.
I decided to drill a hole in the shell for a potentiometer, kind of “in your face” obvious interface. After that I went on trying to figure out how to use the flap door and make it work with an FSR. Hiding a photocell behind the button hole for some extra input, and finally adding a vibrating motor connected to some rattling parts from the zip drive itself to give some nice buzzy feedback. And of course the LED’s. those RGB ones are really fun but hard to figure out how to control at first.
This is how it looked like with all the pieced put in place and a simple “blink” running through the arduino just to make sure everything works as it should, and all that is left is writing the code!
I was aiming to create a neat spectrum effect controlled by the pot, for which I had to map out when to fade each color in and out to get a smooth transition, evidently, this didn’t work too well at first because I didn’t figure out the fading right, and because I didn’t feed the LED’s with enough power using the wrong resistors, and because values over 255 create an odd flickering effect…
This is my finished result, my stupid little, paranoid neurotic with box with shiny spectrum lights. I’m proud of this little thing. Hopefully I’ll make use of the zip drive shell for future projects as a controller of sorts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | int potReadoutPin = 0; // pot pin int fsrReadoutPin = 1; // fsr pin int cellReadoutPin = 2; // cell pin int vibMotorPin = 7; // motor pin int redLEDPin = 8; // red pin int greenLEDPin = 9; // green pin int blueLEDPin = 10; // blue pin int potReadout = 0; // value pot switch int fsrReadout = 0; // value fsr sensor int cellReadout = 0; // value cell sensor int potReadoutPrevious = 0; // var to detect state change int previousCellReadout = 0; // var to detect state change int potPowerout = 0; // output to LED int potZones = 0; // dividing pot areas int potMap = 0; // mapping pot values to map int levelLED = 0; // set LED level int maxLevelLED = 255; // set max LED level int minLevelLED = 0; // set min LED level int fadeLevelLED = 0; // set fade LED level int cellMin = 5; // define darkness int cellMax = 55; // define max lightness int cellMap = 0; // map values o fit max and min long previousMillis = 0; // last time one interval passed long interval = 100; // interval // unused vars int rOn = 0; int gOn = 0; int bOn = 0; void setup () { // start serial Serial.begin(9600); // define pins pinMode (redLEDPin, OUTPUT); pinMode (blueLEDPin, OUTPUT); pinMode (greenLEDPin, OUTPUT); pinMode (vibMotorPin, OUTPUT); pinMode (potReadoutPin, INPUT); pinMode (fsrReadoutPin, INPUT); pinMode (cellReadoutPin, INPUT); } void loop () { // read hidden interface sensors fsrReadout = analogRead(fsrReadoutPin); cellReadout = analogRead(cellReadoutPin); // debug printing // Serial.println(fsrReadout, DEC); // delay(15); potReadout = analogRead(potReadoutPin); // read pot potPowerout = map(potReadout, 0, 1023, 0, 1529); // remap pot to measures of 255 to power LED potZones = map(potReadout, 0 , 1023, 0, 119); // remap pot to define zones for if funct levelLED = potPowerout % 255; // derive LED power value from pot fadeLevelLED = maxLevelLED - levelLED; // derive fade value, opposite to pot int redComp = 100; // compensate problems with red LED resistors cellMap = map(cellReadout, cellMin, cellMax, 0, 500); // map photocell to room conditions Serial.println(cellMap, DEC); // print cell value (debug/adjust) Serial.println(cellReadout, DEC); // print cell value (debug/adjust) if (cellMap>500) { // when far from light sensor - spectrum effect if (potZones > 0 && potZones < 20) { analogWrite (10, levelLED); bOn = 1;} if (potZones >= 20 && potZones < 60) { analogWrite (10, maxLevelLED); bOn = 1; } if (potZones >= 60 && potZones <= 79) { analogWrite (10, fadeLevelLED); bOn = 1; } if (potZones <= 0 || potZones > 79) { analogWrite (10, minLevelLED); bOn = 0; } if (potZones > 40 && potZones < 60) { analogWrite (9, levelLED); gOn = 1;} if (potZones >= 60 && potZones < 100) { analogWrite (9, maxLevelLED); gOn = 1; } if (potZones >= 100 && potZones <= 119) { analogWrite (9, fadeLevelLED); gOn = 1;} if (potZones <= 40 || potZones > 119) { analogWrite (9, minLevelLED); gOn = 0;} if (potZones > 0 && potZones < 20) { analogWrite (8, levelLED+redComp); rOn = 1; } if (potZones >= 20 && potZones < 40) { analogWrite (8, fadeLevelLED-redComp); rOn = 1; } if (potZones >= 40 && potZones <= 80) { analogWrite (8, minLevelLED); rOn = 0; } if (potZones > 80 && potZones < 100) { analogWrite (8, levelLED+redComp); rOn = 1; } if (potZones >= 100) { analogWrite (8, maxLevelLED); rOn = 1; } if (potZones <= 0) { analogWrite (8, minLevelLED); rOn = 0; } } else { if (cellMap<0) { cellMap=10; } // set min value for cellMap if (millis() - previousMillis > interval) { // when close from light sensor - flickering spectrum effect if (potZones > 0 && potZones < 20) { analogWrite (10, levelLED); bOn = 1;} if (potZones >= 20 && potZones < 60) { analogWrite (10, maxLevelLED); bOn = 1; } if (potZones >= 60 && potZones <= 79) { analogWrite (10, fadeLevelLED); bOn = 1; } if (potZones <= 0 || potZones > 79) { analogWrite (10, minLevelLED); bOn = 0; } if (potZones > 40 && potZones < 60) { analogWrite (9, levelLED); gOn = 1;} if (potZones >= 60 && potZones < 100) { analogWrite (9, maxLevelLED); gOn = 1; } if (potZones >= 100 && potZones <= 119) { analogWrite (9, fadeLevelLED); gOn = 1;} if (potZones <= 40 || potZones > 119) { analogWrite (9, minLevelLED); gOn = 0;} if (potZones > 0 && potZones < 20) { analogWrite (8, levelLED+redComp); rOn = 1; } if (potZones >= 20 && potZones < 40) { analogWrite (8, fadeLevelLED-redComp); rOn = 1; } if (potZones >= 40 && potZones <= 80) { analogWrite (8, minLevelLED); rOn = 0; } if (potZones > 80 && potZones < 100) { analogWrite (8, levelLED+redComp); rOn = 1; } if (potZones >= 100) { analogWrite (8, maxLevelLED); rOn = 1; } if (potZones <= 0) { analogWrite (8, minLevelLED); rOn = 0; } delay (cellMap); // blink previousMillis = millis(); // reset interval } else { // kill the lights analogWrite (8, minLevelLED); analogWrite (9, minLevelLED); analogWrite (10, minLevelLED); } } /* if (potReadout < 79 && potReadout > 39) { analogWrite(9, levelLED); } else { analogWrite(9, fadeLED); } */ // if (potReadout != potReadoutPrevious) { // Serial.println(potReadout, DEC); // Serial.println(levelLED, DEC); // potReadoutPrevious = potReadout; // } // delay(15); if (fsrReadout > 400) { // alarm sequence when pushing door for ( int i = 0; i < 5; i++) { digitalWrite(redLEDPin, LOW); digitalWrite(greenLEDPin, LOW); digitalWrite(blueLEDPin, LOW); digitalWrite(redLEDPin, HIGH); digitalWrite(vibMotorPin, HIGH); delay (500); digitalWrite(redLEDPin, LOW); digitalWrite(vibMotorPin, LOW); delay (500); } } } |