#include < MPU6050_tockn.h >
#include < Wire.h >
- MPU6050 Zuko(Wire);
- long timer = 0;
- int lighter = 7;
- int gas = 4;
- int button = 8;
- int gadget =1;
- bool state = false;
- void setup(){
- Wire.begin();
- Zuko.begin();
- pinMode(gas, OUTPUT);
- pinMode(lighter, OUTPUT);
- pinMode(button, INPUT);
- pinMode(9, OUTPUT);
- pinMode(10, OUTPUT);
- pinMode(11, OUTPUT);
- }
- void loop(){
- Zuko.update();
- if ( gadget > 3) // limit to 3 gear only
-
- if ( gadget ==1 )
- Zuko.update();
- digitalWrite(11,LOW); //change the gear light
- digitalWrite(9, HIGH);
- double num1; // variable to store the first acceleration
- if ( millis() - timer > 0){ // first check
-
- for (; Zuko.getAccX() > 5;){ // decline cases where acceleration is too fast to calculate
- Zuko.update()
- }
- num1 = Zuko.getAccX() / 10000000; //store first acceleration
- if ( millis() - timer > 50){ // second check
- Zuko.update();
- }
- if ( Zuko.getAccX() - num1 > 0.9){ // check if it is a punch
-
- if ( state == false){ // avoid too many 'punch' per second that overload device
-
- digitalWrite(lighter, HIGH);
- digitalWrite(gas,HIGH);
- delay(50);
- digitalWrite(gas,LOW);
- digitalWrite(lighter,LOW)
- timer = millis() // reset checking process
- state = true;
- }
- else
-
- }
- }
- }}
- if (gadget == 2){
-
- Zuko.update()
- digitalWrite(9,LOW);
- digitalWrite(10,HIGH);
- double num2;
- for (;Zuko.getAccZ > 5;) {
-
- }
- if ( millis() - timer > 0){
-
- num2 = Zuko.getAccZ() / 10000000;
- if (millis() - timer > 50){
-
- Zuko.update()
- for(;Zuko.getAccZ() > 5;) {
-
- }
- if (abs(Zuko.getAccZ()-num2)>1) {
-
- digitalWrite(lighter,HIGH);
- digitalWrite(gas,HIGH)
- delay(50);
- digitalWrite(gas,LOW);
- digitalWrite(lighter,LOW);
- timer = millis()
- }
- }
- }
- }}
- if ( gadget == 3){
-
- digitalWrite(10,LOW);
- digitalWrite(11,HIGH);
- }
- if ( digitalRead(button) == HIGH){
-
- }
- }
|