Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo servo;
- const int echopin = 4;
- long duration, cm, inches;
- int distance;
- int sensorPin = A0;
- int sensorValue = 0;
- bool actiateBoxingGlove;
- int light;
- void setup(){
- Serial.begin(9600);
- //servo.attach(9);
- //pinMode(echopin, INPUT);
- light = analogRead(sensorPin);
- }
- void loop()
- {
- //Self defence mechanisme punch methode
- //if(actiateBoxingGlove == false){
- // CheckFALCONPUNCH(); }
- //Detect the LightWay
- LightDetection();
- }
- //The self defence mechanisme will now punch.
- void CheckFALCONPUNCH()
- {
- duration = pulseIn(echopin, HIGH);
- distance = duration*0.034/2; //the mathemartical formule for transforming the echo in cm
- Serial.println(distance);
- delay(200);
- if(distance < 31)
- {
- Serial.println("punch");
- ActivateSERVO();
- delay(10);
- }
- }
- //ACTIVATE AWESOME FALCON PUNCH FEATURE
- void ActivateSERVO()
- {
- Serial.println("punch bool = true");
- for(int pos = 0; pos < 180; pos++)
- {
- servo.write(pos);
- delay(1);
- }
- Serial.println("and back");
- for(int pos = 180; pos > 0; pos--)
- {
- servo.write(pos);
- delay(1);
- }
- }
- void LightDetection()
- {
- sensorValue = analogRead(sensorPin); // read the value from the sensor
- Serial.println(sensorValue); //prints the values coming from the sensor on the screen
- //Checking the LIGHTING SENSOR VALUE.
- if(sensorValue < (light - 100)){
- actiateBoxingGlove = false;}
- else{
- actiateBoxingGlove = true;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement