#include /* Test prototype: sound commented out * This version: 3 CapSense Zones: zone1 top of dome, zone2 bottom of dome, zone3 capsule with fetus * * altered CapitiveSense Library Demo Sketch from Paul Badger 2008 * * Using 10M resistor between send pin and receive pin in CapSense */ CapSense cs_7_2 = CapSense(7,2); // pin 2 - zone 1: top half of dome CapSense cs_7_4 = CapSense(7,4); // pin 4 - zone 2: bottom half of dome CapSense cs_7_8 = CapSense(7,8); // pin 8 - zone 3: capsule with fetus long onOff1 = false; //remember the state of touch sensor 1 long onOff2 = false; //remember the state of touch sensor 2 long onOff3 = false; //remember the state of touch sensor 3 int touchVal = 125; //threshold for touch int switchPin = 12; // toggle switch is connected to pin 12: switches between touch & no touch modes int val; // variable for reading the pin status int rLED18 = 18; //pin 18 - red LED: no touch mode, flash int rLED19 = 19; //pin 19 - red LED: no touch mode, flash int wfLED3 = 3; //pin 3 - white LED: fetus in capsul int bLEDcount = 0; int bLEDtotal = 9; int bLEDdelay = 300; int bLED13 = 13; //pins 13, 14, 15, 16 blue blink LEDs int bLED14 = 14; int bLED15 = 15; int bLED16 = 16; int fadeValue = 0; int bfLED5 = 5; //pins 5, 6, 9, 10, 11 blue fade LEDs & blue blink LEDs int bfLED6 = 6; int bfLED9 = 9; int bfLED10 = 10; int bfLED11 = 11; int noTouchNum = 0; //access denied clip long songNum; int minNum = 1; int maxNum = 7; int randomLED = 0; int minLED = 0; int maxLED = 9; int blinkTime = 200; int xTimes = 0; int numTimes = 8; void setup() { cs_7_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example Serial.begin(9600); pinMode(switchPin, INPUT); // Set the switch pin as input pinMode(rLED18, OUTPUT); pinMode(rLED19, OUTPUT); pinMode(wfLED3, OUTPUT); pinMode(bLED13, OUTPUT); //assigned 0 for random numbers pinMode(bLED14, OUTPUT); //assigned 1 for random numbers pinMode(bLED15, OUTPUT); //assigned 2 for random numbers pinMode(bLED16, OUTPUT); //assigned 3 for random numbers pinMode(bfLED5, OUTPUT); //assigned 4 for random numbers pinMode(bfLED6, OUTPUT); //assigned 5 for random numbers pinMode(bfLED9, OUTPUT); //assigned 6 for random numbers pinMode(bfLED10, OUTPUT); //assigned 7 for random numbers pinMode(bfLED11, OUTPUT); //assigned 8 for random numbers //initialize blue LEDs digitalWrite(wfLED3, LOW); digitalWrite(bfLED5, LOW); digitalWrite(bfLED6, LOW); digitalWrite(bfLED9, LOW); digitalWrite(bfLED10, LOW); digitalWrite(bfLED11, LOW); digitalWrite(bLED13, LOW); digitalWrite(bLED14, LOW); digitalWrite(bLED15, LOW); digitalWrite(bLED16, LOW); //while (Serial.read() != '>') ; //initialize, flush out } void loop() { //Check for touch long start = millis(); long total1 = cs_7_2.capSense(30); long total2 = cs_7_4.capSense(30); long total3 = cs_7_8.capSense(30); /* values returned by capSense for serial monitor if (onOff1) onOff1 = total1 >= 100; //hysteresis check else onOff1 = total1 >= 200; if (onOff2) onOff2 = total2 >= 100; //hysteresis check else onOff2 = total2 >= 200; if (onOff3) onOff3 = total3 >= 100; //hysteresis check else onOff3 = total3 >= 200; Serial.print(millis() - start); // check on performance in milliseconds Serial.print("\t"); // tab character for debug windown spacing Serial.print(total1); // print sensor output 1 Serial.print("\t"); Serial.print(onOff1); Serial.print("\t"); Serial.println(total2); // print sensor output 2 Serial.print("\t"); Serial.println(total3); // print sensor output 3 delay(500); // arbitrary delay to limit data to serial port */ val = digitalRead(switchPin); // read input value and store it in val if (val == HIGH) { // check if the toggle is swtiched "on": touch if (total1 > touchVal && total2 <= touchVal && total3 <= touchVal) { // zone 1 only: radiate blues top to bottom & back digitalWrite(bfLED10, HIGH); delay(bLEDdelay); digitalWrite(bfLED9, HIGH); digitalWrite(bfLED11, HIGH); delay(bLEDdelay); digitalWrite(bfLED5, HIGH); digitalWrite(bfLED6, HIGH); delay(bLEDdelay); digitalWrite(bLED13, HIGH); digitalWrite(bLED15, HIGH); delay(bLEDdelay); digitalWrite(bLED14, HIGH); digitalWrite(bLED16, HIGH); delay(bLEDdelay); digitalWrite(bLED14, LOW); digitalWrite(bLED16, LOW); delay(bLEDdelay); digitalWrite(bLED13, LOW); digitalWrite(bLED15, LOW); delay(bLEDdelay); digitalWrite(bfLED5, LOW); digitalWrite(bfLED6, LOW); delay(bLEDdelay); digitalWrite(bfLED9, LOW); digitalWrite(bfLED11, LOW); delay(bLEDdelay); digitalWrite(bfLED10, LOW); delay(bLEDdelay); } //end of zone 1 only touch if (total2 > touchVal && total1 <= touchVal && total3 <= touchVal) { // zone 2 only: //5 blue LEDs fade in in increments of 3 points for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=3) { // sets the value (range from 0 to 255): analogWrite(bfLED10, fadeValue); analogWrite(bfLED9, fadeValue); analogWrite(bfLED11, fadeValue); analogWrite(bfLED5, fadeValue); analogWrite(bfLED6, fadeValue); // wait for 30 milliseconds to see the brightening effect delay(30); } // 5 blue LEDs fade out in increments of 3 points for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=3) { // sets the value (range from 0 to 255) analogWrite(bfLED10, fadeValue); analogWrite(bfLED9, fadeValue); analogWrite(bfLED11, fadeValue); analogWrite(bfLED5, fadeValue); analogWrite(bfLED6, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } } //end of zone 2 only touch if (total3 > touchVal && total1 <= touchVal && total2 <= touchVal) { //zone 3 only: //fetus white fade in in increments of 3 points for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=3) { // sets the value (range from 0 to 255): analogWrite(wfLED3, fadeValue); //wait for 30 Milliseconds to see brightening effect delay(30); } //fetus white fade out in increments of 3 points for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=3) { // sets the value (range from 0 to 255) analogWrite(wfLED3, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } } //end of zone 3 only touch if ((total1 > touchVal && total2 > touchVal) || (total2 > touchVal && total3 > touchVal)) { // (zone 1 and zone 2) or (zone 2 and zone 3) //random blue LEDs blink while a sound clip plays /* songNum = random(minNum, maxNum); Serial.print("PC F "); Serial.print(songNum, DEC); Serial.print(".mp3\r"); while (Serial.read() != '>') { } //flush out to be ready for a cmd Serial.print("PC Z\r"); //check for play status while (Serial.read() != 'S') { */ //random blink blue LEDs randomLED = random(minLED, maxLED); if (randomLED = 0) { digitalWrite(bLED13, HIGH); delay (blinkTime); digitalWrite(bLED13, LOW); } if (randomLED = 1) { digitalWrite(bLED14, HIGH); delay (blinkTime); digitalWrite(bLED14, LOW); } if (randomLED = 2) { digitalWrite(bLED15, HIGH); delay (blinkTime); digitalWrite(bLED15, LOW); } if (randomLED = 3) { digitalWrite(bLED16, HIGH); delay (blinkTime); digitalWrite(bLED16, LOW); } if (randomLED = 4) { digitalWrite(bfLED5, HIGH); delay (blinkTime); digitalWrite(bfLED5, LOW); } if (randomLED = 5) { digitalWrite(bfLED6, HIGH); delay (blinkTime); digitalWrite(bfLED6, LOW); } if (randomLED = 6) { digitalWrite(bfLED9, HIGH); delay (blinkTime); digitalWrite(bfLED9, LOW); } if (randomLED = 7) { digitalWrite(bfLED10, HIGH); delay (blinkTime); digitalWrite(bfLED10, LOW); } if (randomLED = 8) { digitalWrite(bfLED11, HIGH); delay (blinkTime); digitalWrite(bfLED11, LOW); } /* while (Serial.read() != '>') { } //flush out Serial.print("PC Z\r"); } while (Serial.read() != '>') { } //flush out */ } //ends (zone 1 and zone 2) or (zone 2 and zone 4) touch if (total1 > touchVal && total3 > touchVal && total2 <= touchVal) { //zone 1 and zone 3: //fade white fetus LED, then radiate blue LEDS, then fade white fetus LED /* test without - too slow with //fetus white fade in in increments of 3 points for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=3) { // sets the value (range from 0 to 255): analogWrite(wfLED3, fadeValue); //wait for 30 Milliseconds to see brightening effect delay(30); } //fetus white fade out in increments of 3 points for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=3) { // sets the value (range from 0 to 255) analogWrite(wfLED3, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } */ //radiate blues top to bottom and back digitalWrite(bfLED10, HIGH); delay(bLEDdelay); digitalWrite(bfLED9, HIGH); digitalWrite(bfLED11, HIGH); delay(bLEDdelay); digitalWrite(bfLED5, HIGH); digitalWrite(bfLED6, HIGH); delay(bLEDdelay); digitalWrite(bLED13, HIGH); digitalWrite(bLED15, HIGH); delay(bLEDdelay); digitalWrite(bLED14, HIGH); digitalWrite(bLED16, HIGH); delay(bLEDdelay); digitalWrite(bLED14, LOW); digitalWrite(bLED16, LOW); delay(bLEDdelay); digitalWrite(bLED13, LOW); digitalWrite(bLED15, LOW); delay(bLEDdelay); digitalWrite(bfLED5, LOW); digitalWrite(bfLED6, LOW); delay(bLEDdelay); digitalWrite(bfLED9, LOW); digitalWrite(bfLED11, LOW); delay(bLEDdelay); digitalWrite(bfLED10, LOW); delay(bLEDdelay); //fetus white fade in in increments of 3 points for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=3) { // sets the value (range from 0 to 255): analogWrite(wfLED3, fadeValue); //wait for 30 Milliseconds to see brightening effect delay(30); } //fetus white fade out in increments of 3 points for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=3) { // sets the value (range from 0 to 255) analogWrite(wfLED3, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } } //end of zone 1 and zone 3 touch } //end of touch OK //check if the toggle is "off": no touch if (val == LOW) { if (total1 > touchVal || total2 > touchVal || total3 > touchVal) //touch while no touch mode { for (int xTimes = 0; xTimes <= numTimes; xTimes++) { digitalWrite(rLED18, HIGH); // set warning red LED pin 18 on digitalWrite(rLED19, HIGH); // set warning red LED pin 19 on delay(200); digitalWrite(rLED18, LOW); // set warning LEDS off digitalWrite(rLED19, LOW); delay(200); } /* //call for access denied clip Serial.print("PC F "); Serial.print(noTouchNum, DEC); Serial.print(".mp3\r"); while (Serial.read() != '>') { } //flush out to be ready for a cmd Serial.print("PC Z\r"); //check for play status while (Serial.read() != 'S') { while (Serial.read() != '>') { } //flush out Serial.print("PC Z\r"); } while (Serial.read() != '>') { } //flush out to be ready for a cmd */ } } //end of touch not OK } //end of void loop()