Created
December 5, 2025 14:25
-
-
Save terremoth/67d1f08603d498388197561046dd8e75 to your computer and use it in GitHub Desktop.
Comportamento do urso - roboi de mamão
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Servo.h> // Include the Servo library | |
| Servo myServo; // Create a Servo object | |
| const int SonarTrigger = 7; // define o pino 7 como Trigger | |
| const int SonarEcho = 8; // define o pino 6 como Echo | |
| const int led_olhos = 9; | |
| const int buzzer = 10; | |
| const int servo = 11; // Pino do servo | |
| float distancia = 0; // Use float para a distância (em cm) | |
| unsigned long tempo = 0; // Use unsigned long para o tempo (microssegundos) | |
| void setup() { | |
| pinMode(buzzer, OUTPUT); | |
| pinMode(led_olhos, OUTPUT); | |
| pinMode(SonarTrigger, OUTPUT); // Função de emitir o som (altofalante - Saída) | |
| pinMode(SonarEcho, INPUT); //Função de receber um som (microfone - Entrada) | |
| myServo.attach(servo); | |
| Serial.begin(9600); // Para escrever no monitor serial | |
| } | |
| void loop() { | |
| digitalWrite(SonarTrigger, LOW); // Estabiliza sensor | |
| delay(2); | |
| digitalWrite(SonarTrigger, HIGH); // Envia um pulso para ativar | |
| delay(10); | |
| digitalWrite(SonarTrigger, LOW); | |
| tempo = pulseIn(SonarEcho, HIGH); // Função que recebe um pulso e retorna o valor em tempo da duração deste pulso, em microsegundos | |
| distancia = tempo / 58.2; // Distancia = tempo * velocidade do som / 2 (Velocidade do som é 340 m/s) | |
| digitalWrite(led_olhos, LOW); | |
| myServo.write(0); | |
| Serial.print("Medir: "); | |
| Serial.println(distancia); | |
| if (distancia < 20 && distancia > 3) { | |
| digitalWrite(led_olhos, HIGH); | |
| Serial.println("mexe servo"); | |
| myServo.write(100); | |
| distancia = 0; // resolve bugs que até budha duvidaria em sua mais alta consciência | |
| for (int i = 75; i > 30; i--) { | |
| tone(buzzer, i); | |
| delay(25); | |
| } | |
| noTone(buzzer); | |
| distancia = 0; // resolve bugs que até budha duvidaria em sua mais alta consciência | |
| } | |
| distancia = 0; // resolve bugs que até budha duvidaria em sua mais alta consciência | |
| delay(100); // Mede a cada 1 segundo | |
| distancia = 0; // resolve bugs que até budha duvidaria em sua mais alta consciência | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment