SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
/* This sketch demonstrates the following features:
      1) Button Debouncing - used to eliminate random HIGH/
LOW signals during button press/release
      2) Continuous BLE broadcasting until the RFduino exhibits a system reset
      3) Implementation to switch between different states upon 'ACTION' press:
            -> Begins at state '0' at start-up
            -> State transition: 0-1-0 after single ACTION press
            -> State transition: 0-2 after hold event
      4) Single ACTION press -> sends sms to emergency contact with gps co-ordinates
                             -> activates continuous buzzer tone until hold event occurs
      5) Hold ACTION event -> calls emergency contact 
      6) ON/OFF switch to turn off module -> single buzzer tone to signify power ON 
*/
#include <RFduinoBLE.h>
#define ACTIONbutton 4    // GPIO4 used to track button press events
#define speaker 5         // GPIO5 used to activate speaker/buzzer
#define monitBatt 6       // GIPIO used to monitor battery level of the module
#define holdTime 1000     // how long to wait for press + hold event (hold period in
milliseconds)
#define debounce 1     // debounce period (in milliseconds) to prevent flickering when
pressing or releasing the ACTION button
int buttonVal = 0; // value read from ACTION button
int buttonLast = 0; // buffered value of the ACTION button's previous state
int ledState = -1; // Keeps track of the state of ACTION1
int stateEvent = 0; // Keeps track of the state of ACTION2
long btnDnTime=0; // time the button was pressed down
long btnUpTime=0; // time the button was released
boolean ignoreUp = false; // whether to ignore the button release due to click & hold
being triggered
float analogON_OFF; // analog voltage reading from "ON_OFF" output
float voltageON_OFF; // digital voltage reading from "ON_OFF" output
// Code below is run only once
void setup() {
  Serial.begin(9600);
  RFduinoBLE.deviceName = "Victor's RFduino"; // Set the BLE device name
  RFduinoBLE.customUUID = "5eaca154-b39c-4235-af14-dc4db932d10c"; // Create
a unique and custom UUID
  RFduinoBLE.advertisementInterval = 100;
  RFduinoBLE.begin(); // Start BLE broadcasting
  
  RFduinoBLE.txPowerLevel = -20; // Set the BLE transmit power to -20 dBm
(Decibels per milliwatts)
  pinMode(ACTIONbutton,INPUT); // Set the ACTION button as an input
(GPIO4)
  pinMode(speaker,OUTPUT); // Set the speaker output (GPIO5)
  startUp();
}
// Code below runs forever
void loop()
{ 
  analogON_OFF = analogRead(monitBatt);
  voltageON_OFF = 3.5*analogON_OFF/1023;
  
  // For arduino testing purposes ONLY
  if (voltageON_OFF <= 3.25){
    Serial.print("Low Battery Warning: Please recharge the battery!");
  else if (voltageON_OFF > 3.25){
    Serial.print("/nBattery is healthy!");
  }
    
  // At low battery, there will be two quick beeps and a long delay
  // Bluetooth will also be turned off
  while (voltageON_OFF < 3.25){
    RFduinoBLE.end();
    lowBattWarn();
    delay(500);
  }
  
  buttonVal = digitalRead(ACTIONbutton);
    
  // Test for button pressed and store the down time
  if (buttonVal == HIGH && buttonLast == LOW && (millis() - btnUpTime) >
long(debounce)){
    btnDnTime = millis(); // Store the down time
  }
  
   // Test for button release and store the up time
   if (buttonVal == LOW && buttonLast == HIGH && (millis() - btnDnTime) >
long(debounce)){
     if (ignoreUp == false){ // "FALSE" only if the ACTION button is tapped once
       
       stateEvent = 1;
       
       if (stateEvent == 1){
         stateEvent1();
       }
       
       delay(150);
       
       if (stateEvent == 0){
         stateEvent0();
       }
     
     }
     else{
       ignoreUp == false;
     }
    
     btnUpTime = millis(); // Store the up time
   }
  
   // Test for button held down for longer than the hold time
   if (buttonVal == HIGH && (millis() - btnDnTime) > long(holdTime)){
      stateEvent = 2;
      
      while (stateEvent == 2){
        stateEvent2();
      }
      
     ignoreUp = true; // "TRUE" only if the ACTION button is held
     btnDnTime = millis(); // Store down time
   }
  
     buttonLast = buttonVal;
}
// After initiating bluetooth connection, send an INT value of 0 through BLE
void RFduinoBLE_onConnect(){
  Serial.println("Bluetooth has been connected!");
  RFduinoBLE.sendByte(0);
}
// Tell the user when the device loses bluetooth connection
void RFduinoBLE_onDisconnect(){
  Serial.println("Bluetooth has been disconnected!");
}
// 'Home' state event
void stateEvent0(){
  RFduinoBLE.sendByte(0);
}
// First ACTION state event
void stateEvent1(){
  RFduinoBLE.sendByte(1);
  tone(5,60); // Generate a tone after first ACTION event
  delay(100); // Delay used for repeating beeps
  stateEvent = 0;
}
// Second ACTION state event
void stateEvent2(){
  noTone(5); // Turn off tone after second ACTION event
  RFduinoBLE.sendByte(2);
}
// Two quick beeps at POWER ON 
void startUp(){
  for (int i=0; i <= 2; i++){
    digitalWrite(speaker,HIGH);
    delay(100);
    digitalWrite(speaker,LOW);
  }
}
// Two quick beeps then a long delay at low battery
void lowBattWarn(){
  for (int j=0; j<=2; j++){
    digitalWrite(speaker,HIGH);
    delay(100);
    digitalWrite(speaker,LOW);
  }
}
  

Más contenido relacionado

La actualidad más candente

Programmable systems-outcome-12
Programmable systems-outcome-12Programmable systems-outcome-12
Programmable systems-outcome-12doovood
 
Semester project report_Prafulla_Kumar_Shahi
Semester project report_Prafulla_Kumar_ShahiSemester project report_Prafulla_Kumar_Shahi
Semester project report_Prafulla_Kumar_ShahiPrafulla Kumar Shahi
 
Changable tundra electronics customize parameters
Changable tundra electronics customize parameters Changable tundra electronics customize parameters
Changable tundra electronics customize parameters buyobdii
 
ASL Intercom PS260T
ASL Intercom PS260TASL Intercom PS260T
ASL Intercom PS260TAV ProfShop
 
Cataloge ge 3.control and_automation_dienhathe.com-4_19_vat300_e_c6-6-3_2_rev_c1
Cataloge ge 3.control and_automation_dienhathe.com-4_19_vat300_e_c6-6-3_2_rev_c1Cataloge ge 3.control and_automation_dienhathe.com-4_19_vat300_e_c6-6-3_2_rev_c1
Cataloge ge 3.control and_automation_dienhathe.com-4_19_vat300_e_c6-6-3_2_rev_c1Dien Ha The
 
TraceTek TT-TS12 touch screen controller
TraceTek TT-TS12 touch screen controllerTraceTek TT-TS12 touch screen controller
TraceTek TT-TS12 touch screen controllerpentairthermal
 

La actualidad más candente (7)

Programmable systems-outcome-12
Programmable systems-outcome-12Programmable systems-outcome-12
Programmable systems-outcome-12
 
Semester project report_Prafulla_Kumar_Shahi
Semester project report_Prafulla_Kumar_ShahiSemester project report_Prafulla_Kumar_Shahi
Semester project report_Prafulla_Kumar_Shahi
 
Changable tundra electronics customize parameters
Changable tundra electronics customize parameters Changable tundra electronics customize parameters
Changable tundra electronics customize parameters
 
ASL Intercom PS260T
ASL Intercom PS260TASL Intercom PS260T
ASL Intercom PS260T
 
Cataloge ge 3.control and_automation_dienhathe.com-4_19_vat300_e_c6-6-3_2_rev_c1
Cataloge ge 3.control and_automation_dienhathe.com-4_19_vat300_e_c6-6-3_2_rev_c1Cataloge ge 3.control and_automation_dienhathe.com-4_19_vat300_e_c6-6-3_2_rev_c1
Cataloge ge 3.control and_automation_dienhathe.com-4_19_vat300_e_c6-6-3_2_rev_c1
 
TraceTek TT-TS12 touch screen controller
TraceTek TT-TS12 touch screen controllerTraceTek TT-TS12 touch screen controller
TraceTek TT-TS12 touch screen controller
 
ZME WALLC-S manual
ZME WALLC-S manualZME WALLC-S manual
ZME WALLC-S manual
 

Destacado

Learning new tricks: how social media is revolutionising the role of the PR p...
Learning new tricks: how social media is revolutionising the role of the PR p...Learning new tricks: how social media is revolutionising the role of the PR p...
Learning new tricks: how social media is revolutionising the role of the PR p...Tracy Playle
 
The role of the social media in corporate PR practice using the Ukrainian con...
The role of the social media in corporate PR practice using the Ukrainian con...The role of the social media in corporate PR practice using the Ukrainian con...
The role of the social media in corporate PR practice using the Ukrainian con...HOSHVA PR
 
Nm3219 pr plan presentation (singapore red cross)
Nm3219 pr plan presentation (singapore red cross)Nm3219 pr plan presentation (singapore red cross)
Nm3219 pr plan presentation (singapore red cross)AzmiSuhaimi
 
Social Media and PR 2.0
Social Media and PR 2.0Social Media and PR 2.0
Social Media and PR 2.0Jame Ervin
 
The Power of Social Media in a PR Campaign
The Power of Social Media in a PR CampaignThe Power of Social Media in a PR Campaign
The Power of Social Media in a PR Campaignguest13fa457
 
State of emergency in India
State of emergency in IndiaState of emergency in India
State of emergency in IndiaRohit Gupta
 
State of emergency
State of emergencyState of emergency
State of emergencyaps1986
 
Understanding the Role of the Media - Napier PR
Understanding the Role of the Media - Napier PRUnderstanding the Role of the Media - Napier PR
Understanding the Role of the Media - Napier PRNapierPR
 
iPress per PR e Comunicatori
iPress per PR e ComunicatoriiPress per PR e Comunicatori
iPress per PR e ComunicatoriiPress
 
Mapping The Consequences Of Technology On Public Relations
Mapping The Consequences Of Technology On Public RelationsMapping The Consequences Of Technology On Public Relations
Mapping The Consequences Of Technology On Public Relationsmctripletwo
 
Freedom of expression.
Freedom of expression.Freedom of expression.
Freedom of expression.noeliaiiiiii
 
Freedom of expression
Freedom of expressionFreedom of expression
Freedom of expressionGerwin Ocsena
 
Freedom of Speech & Expression
Freedom of Speech & ExpressionFreedom of Speech & Expression
Freedom of Speech & Expressiongcundiff
 
Freedom of Expression is a Human Right
Freedom of Expression is a Human RightFreedom of Expression is a Human Right
Freedom of Expression is a Human RightStresemann Stiftung
 
Emergency Provisions
Emergency ProvisionsEmergency Provisions
Emergency Provisionssufi shahi
 

Destacado (19)

Learning new tricks: how social media is revolutionising the role of the PR p...
Learning new tricks: how social media is revolutionising the role of the PR p...Learning new tricks: how social media is revolutionising the role of the PR p...
Learning new tricks: how social media is revolutionising the role of the PR p...
 
The role of the social media in corporate PR practice using the Ukrainian con...
The role of the social media in corporate PR practice using the Ukrainian con...The role of the social media in corporate PR practice using the Ukrainian con...
The role of the social media in corporate PR practice using the Ukrainian con...
 
USC Emerging Technologies and Public Relations
USC Emerging Technologies and Public RelationsUSC Emerging Technologies and Public Relations
USC Emerging Technologies and Public Relations
 
Nm3219 pr plan presentation (singapore red cross)
Nm3219 pr plan presentation (singapore red cross)Nm3219 pr plan presentation (singapore red cross)
Nm3219 pr plan presentation (singapore red cross)
 
Social Media and PR 2.0
Social Media and PR 2.0Social Media and PR 2.0
Social Media and PR 2.0
 
The Power of Social Media in a PR Campaign
The Power of Social Media in a PR CampaignThe Power of Social Media in a PR Campaign
The Power of Social Media in a PR Campaign
 
State of emergency in India
State of emergency in IndiaState of emergency in India
State of emergency in India
 
State of emergency
State of emergencyState of emergency
State of emergency
 
Understanding the Role of the Media - Napier PR
Understanding the Role of the Media - Napier PRUnderstanding the Role of the Media - Napier PR
Understanding the Role of the Media - Napier PR
 
iPress per PR e Comunicatori
iPress per PR e ComunicatoriiPress per PR e Comunicatori
iPress per PR e Comunicatori
 
Mapping The Consequences Of Technology On Public Relations
Mapping The Consequences Of Technology On Public RelationsMapping The Consequences Of Technology On Public Relations
Mapping The Consequences Of Technology On Public Relations
 
Freedom of expression.
Freedom of expression.Freedom of expression.
Freedom of expression.
 
PR & Social Media (e-learning)
PR & Social Media (e-learning)PR & Social Media (e-learning)
PR & Social Media (e-learning)
 
Freedom of expression
Freedom of expressionFreedom of expression
Freedom of expression
 
PR 2.0 (1)
PR 2.0 (1)PR 2.0 (1)
PR 2.0 (1)
 
Freedom of Speech & Expression
Freedom of Speech & ExpressionFreedom of Speech & Expression
Freedom of Speech & Expression
 
What’S Your E Pr Strategy
What’S Your E Pr StrategyWhat’S Your E Pr Strategy
What’S Your E Pr Strategy
 
Freedom of Expression is a Human Right
Freedom of Expression is a Human RightFreedom of Expression is a Human Right
Freedom of Expression is a Human Right
 
Emergency Provisions
Emergency ProvisionsEmergency Provisions
Emergency Provisions
 

Similar a Untitled

POPP. 4-button remote control key Z-WAVE
POPP. 4-button remote control key Z-WAVEPOPP. 4-button remote control key Z-WAVE
POPP. 4-button remote control key Z-WAVEDomotica daVinci
 
Program Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdfProgram Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdfrajkumarm401
 
Wall Controller 4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
Wall Controller	4 Buttons rechargeable Remote Z-Wave Plus - Hank manualWall Controller	4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
Wall Controller 4 Buttons rechargeable Remote Z-Wave Plus - Hank manualDomotica daVinci
 
Kjr 29 b (termostato alam. fan coil)
Kjr 29 b (termostato alam. fan coil)Kjr 29 b (termostato alam. fan coil)
Kjr 29 b (termostato alam. fan coil)German Nava
 
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22josnihmurni2907
 
Aeotec Multisensor 7 Manual
Aeotec Multisensor 7 ManualAeotec Multisensor 7 Manual
Aeotec Multisensor 7 ManualDomotica daVinci
 
20070903200911140 Eurok4 Tm 0719
20070903200911140 Eurok4 Tm 071920070903200911140 Eurok4 Tm 0719
20070903200911140 Eurok4 Tm 0719manxx
 
honeywell-dc1000-dc1010-dc1030-dc1040-manual.pdf
honeywell-dc1000-dc1010-dc1030-dc1040-manual.pdfhoneywell-dc1000-dc1010-dc1030-dc1040-manual.pdf
honeywell-dc1000-dc1010-dc1030-dc1040-manual.pdfssuserbe139c
 
how to use Mst1000 motor ingiting signal
how to use Mst1000 motor ingiting signalhow to use Mst1000 motor ingiting signal
how to use Mst1000 motor ingiting signalEnzo C
 
Router and switch basics configuration
Router and switch basics configurationRouter and switch basics configuration
Router and switch basics configurationMissangae
 
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2SANTIAGO PABLO ALBERTO
 
Hướng dẫn sử dụng máy đo tốc độ gió và nhiệt độ Extech 407113
Hướng dẫn sử dụng máy đo tốc độ gió và nhiệt độ Extech 407113Hướng dẫn sử dụng máy đo tốc độ gió và nhiệt độ Extech 407113
Hướng dẫn sử dụng máy đo tốc độ gió và nhiệt độ Extech 407113Tenmars Việt Nam
 
Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...
Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...
Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...IT Event
 
System Administration: Linux Process
System Administration: Linux ProcessSystem Administration: Linux Process
System Administration: Linux Processlucita cabral
 

Similar a Untitled (20)

POPP. 4-button remote control key Z-WAVE
POPP. 4-button remote control key Z-WAVEPOPP. 4-button remote control key Z-WAVE
POPP. 4-button remote control key Z-WAVE
 
Program Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdfProgram Structure declare ButtonState Global variable holding statu.pdf
Program Structure declare ButtonState Global variable holding statu.pdf
 
Wall Controller 4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
Wall Controller	4 Buttons rechargeable Remote Z-Wave Plus - Hank manualWall Controller	4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
Wall Controller 4 Buttons rechargeable Remote Z-Wave Plus - Hank manual
 
Kjr 29 b (termostato alam. fan coil)
Kjr 29 b (termostato alam. fan coil)Kjr 29 b (termostato alam. fan coil)
Kjr 29 b (termostato alam. fan coil)
 
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
 
Mic1462 quick start_[1738]
Mic1462 quick start_[1738]Mic1462 quick start_[1738]
Mic1462 quick start_[1738]
 
Aeotec Multisensor 7 Manual
Aeotec Multisensor 7 ManualAeotec Multisensor 7 Manual
Aeotec Multisensor 7 Manual
 
20070903200911140 Eurok4 Tm 0719
20070903200911140 Eurok4 Tm 071920070903200911140 Eurok4 Tm 0719
20070903200911140 Eurok4 Tm 0719
 
honeywell-dc1000-dc1010-dc1030-dc1040-manual.pdf
honeywell-dc1000-dc1010-dc1030-dc1040-manual.pdfhoneywell-dc1000-dc1010-dc1030-dc1040-manual.pdf
honeywell-dc1000-dc1010-dc1030-dc1040-manual.pdf
 
how to use Mst1000 motor ingiting signal
how to use Mst1000 motor ingiting signalhow to use Mst1000 motor ingiting signal
how to use Mst1000 motor ingiting signal
 
MK1_Addendum
MK1_AddendumMK1_Addendum
MK1_Addendum
 
Router and switch basics configuration
Router and switch basics configurationRouter and switch basics configuration
Router and switch basics configuration
 
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
 
Hướng dẫn sử dụng máy đo tốc độ gió và nhiệt độ Extech 407113
Hướng dẫn sử dụng máy đo tốc độ gió và nhiệt độ Extech 407113Hướng dẫn sử dụng máy đo tốc độ gió và nhiệt độ Extech 407113
Hướng dẫn sử dụng máy đo tốc độ gió và nhiệt độ Extech 407113
 
ZME WALLC-S manual
ZME WALLC-S manualZME WALLC-S manual
ZME WALLC-S manual
 
Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...
Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...
Alberto Guarino "When iPhones and Wearables Dance the Bluetooth Dance: Lesson...
 
239428174 monitor
239428174 monitor239428174 monitor
239428174 monitor
 
System Administration: Linux Process
System Administration: Linux ProcessSystem Administration: Linux Process
System Administration: Linux Process
 
Philio_pan08_manual
Philio_pan08_manualPhilio_pan08_manual
Philio_pan08_manual
 
The Consultants Role
The Consultants RoleThe Consultants Role
The Consultants Role
 

Untitled