Advertisement
Guest User

Untitled

a guest
May 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo servo;
  4.  
  5. const int echopin = 4;
  6. long duration, cm, inches;
  7. int distance;
  8.  
  9. int sensorPin = A0;
  10. int sensorValue = 0;
  11. bool actiateBoxingGlove;
  12. int light;
  13.  
  14. void setup(){
  15.   Serial.begin(9600);
  16.   //servo.attach(9);
  17.   //pinMode(echopin, INPUT);
  18.   light = analogRead(sensorPin);
  19. }
  20.  
  21. void loop()
  22. {
  23.   //Self defence mechanisme punch methode
  24.   //if(actiateBoxingGlove == false){
  25.    // CheckFALCONPUNCH();  }
  26.  
  27.   //Detect the LightWay
  28.   LightDetection();
  29. }
  30.  
  31. //The self defence mechanisme will now punch.
  32. void CheckFALCONPUNCH()
  33. {
  34.   duration = pulseIn(echopin, HIGH);
  35.  
  36.  
  37.   distance = duration*0.034/2; //the mathemartical formule for transforming the echo in cm
  38.   Serial.println(distance);
  39.   delay(200);
  40.  
  41.   if(distance < 31)
  42.   {
  43.     Serial.println("punch");
  44.     ActivateSERVO();
  45.     delay(10);
  46.   }
  47. }
  48.  
  49. //ACTIVATE AWESOME FALCON PUNCH FEATURE
  50. void ActivateSERVO()
  51. {
  52.    Serial.println("punch bool = true");
  53.     for(int pos  = 0; pos < 180; pos++)
  54.     {
  55.     servo.write(pos);
  56.     delay(1);
  57.     }
  58.  
  59.     Serial.println("and back");
  60.    
  61.     for(int pos  = 180; pos > 0; pos--)
  62.     {
  63.     servo.write(pos);
  64.     delay(1);
  65.     }
  66. }
  67.  
  68. void LightDetection()
  69. {
  70.   sensorValue = analogRead(sensorPin); // read the value from the sensor
  71.   Serial.println(sensorValue); //prints the values coming from the sensor on the screen
  72.  
  73.   //Checking the LIGHTING SENSOR VALUE.
  74.   if(sensorValue < (light - 100)){
  75.     actiateBoxingGlove = false;}
  76.   else{
  77.     actiateBoxingGlove = true;}
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement