aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@ziggy.(none)>2009-09-14 00:55:33 -0400
committerbnewbold <bnewbold@ziggy.(none)>2009-09-14 00:55:33 -0400
commit0266ef7913c9817bd1c969dc7fe15809042128f0 (patch)
tree3c95d61d15352a315174bbf649a68a9506623d43
parent89d5a773a7469dd6897fc499cdd8437fdb87e6a0 (diff)
downloadpysqrls-0266ef7913c9817bd1c969dc7fe15809042128f0.tar.gz
pysqrls-0266ef7913c9817bd1c969dc7fe15809042128f0.zip
real stuff now! incorporated pseudo code
-rw-r--r--src/virtual_sqrl/virtual_sqrl.pde154
1 files changed, 154 insertions, 0 deletions
diff --git a/src/virtual_sqrl/virtual_sqrl.pde b/src/virtual_sqrl/virtual_sqrl.pde
new file mode 100644
index 0000000..c7b7e47
--- /dev/null
+++ b/src/virtual_sqrl/virtual_sqrl.pde
@@ -0,0 +1,154 @@
+#include <MsTimer2.h>
+
+/*
+ * Virtual SQRLS Program
+ *
+ * Requires the Metro Arduino libary: http://www.arduino.cc/playground/Code/Metro
+ */
+
+int speakerOnePin = 5;
+int speakerTwoPin = 6;
+int activeSpeaker = speakerOnePin;
+int volumePin = 9;
+int motionSensorPin = 3;
+int defaultVolume=12;
+int b = 0;
+int bb = 0;
+int OCC=0;
+int TSL=0;
+int TIM=0;
+boolean logicLock = 0;
+
+
+void setup() {
+ noInterrupts();
+ pinMode(motionSensorPin, INPUT);
+ pinMode(speakerOnePin, OUTPUT);
+ pinMode(speakerTwoPin, OUTPUT);
+ pinMode(volumePin, OUTPUT);
+ // Set pins 5&6 to a 62500Hz PWM clock
+ TCCR0B = TCCR0B & 0b11111000 | 0x01;
+ TCCR1B = TCCR1B & 0b11111000 | 0x01;
+
+ TIM = random(200,400);
+
+ // Sets a starting volume
+ analogWrite(volumePin,defaultVolume);
+
+ MsTimer2::set(10, handleLogic); // 10ms period
+ MsTimer2::start();
+
+ // interrupt 1 = pin 3
+ attachInterrupt(1, motionOn, RISING);
+ attachInterrupt(1, motionOff, FALLING);
+
+ interrupts();
+}
+
+void loop(){
+}
+
+void handleLogic() {
+ if(logicLock) {
+ return;
+ }
+ logicLock = 1;
+ TSL++;
+ if(TSL=TIM){
+ caw(3);
+ } else if (TSL = 2*TIM) {
+ caw(4);
+ caw(5);
+ } else if (TSL = 2*TIM+30) {
+ caw(3);
+ caw(4);
+ caw(5);
+ OCC--;
+ } else if (TSL = 2*TIM+50) {
+ if(OCC<0){
+ caw(4);
+ caw(5);
+ caw(6);
+ caw(7);
+ barker(6);
+ }
+ } else if(TSL % (2*TIM+50) == 0) {
+ caw(1);
+ caw(2);
+ OCC--;
+ }
+
+ if(TSL > 10000) {
+ TSL = 0;
+ }
+ logicLock = 0;
+}
+
+void motionOn() {
+ analogWrite(volumePin, 0);
+ if(TSL>200) {
+ OCC++;
+ }
+}
+
+void motionOff() {
+ analogWrite(volumePin, defaultVolume);
+ TSL=0;
+ TIM = random(200,400);
+}
+
+// Caw sound. eg,
+// caw(1000);
+// delay(200000);
+void caw(int ll) {
+ for(int j=1800; j<1900; j+=1000/ll) {
+ if(j<1816){
+ analogWrite(volumePin,(j-1815)*4/5+12);
+ }
+ if(j>1875){
+ analogWrite(volumePin,(1875-j)/4+12);
+ }
+ b++;
+ if (b==10){
+ bb=1;
+ b=0;
+ }
+ sawWave(j/8+500*bb+random(10));
+ bb=0;
+ }
+}
+
+
+// Bark sound. eg,
+// barker(random(3));
+void barker(int num) {
+ for(int u=0;u<num;u++){
+ bark(random(50,80)^2/100);
+ delay(random(50000,200000)^2/100000);
+ }
+}
+void bark(int ll) {
+
+ for(int j=500; j>200; j-=3000/ll) {
+ sawWave(j+random(50));
+ }
+
+}
+
+// Generic triangle wave sound
+void triangleWave(int len) {
+
+ for(int i = 0; i < len; i++) {
+ analogWrite(activeSpeaker, i*255/len);
+ }
+ for(int i = 0; i < len; i++) {
+ analogWrite(activeSpeaker, 255 - i*255/len);
+ }
+}
+
+// Generic saw wave sound
+void sawWave(int len) {
+ for(int i = 0; i < len; i++) {
+ analogWrite(activeSpeaker, i);
+ }
+}