#include Servo myServo; // Pins const int trigPinTrash = 7;
Ich habe hier etwas Einzigartiges, das zu dir passt.
#include Servo myServo; // Pins const int trigPinTrash = 7; // Trigger pin of ultrasonic sensor for trash const int echoPinTrash = 6; // Echo pin of ultrasonic sensor for trash const int trigPinServo = 4; // Trigger pin of ultrasonic sensor for servo const int echoPinServo = 5; // Echo pin of ultrasonic sensor for servo const int servoPin = 9; // Servo control pin const int buzzerPin = 3; // Buzzer pin // Thresholds const float trashThreshold = 16.0; // Threshold distance for trash in cm const float servoThreshold = 15.0; // Threshold distance for servo in cm // Timers unsigned long lastMessageTime = 0; // Time for last message unsigned long lastServoMoveTime = 0; // Last time servo moved const unsigned long messageInterval = 5000; // Message interval for trash status const unsigned long openDuration = 5000; // Servo open duration // State variables bool isServoOpen = false; // Servo open status bool isTrashFull = false; // Trash full status void setup() { pinMode(trigPinTrash, OUTPUT); pinMode(echoPinTrash, INPUT); pinMode(trigPinServo, OUTPUT); pinMode(echoPinServo, INPUT); pinMode(buzzerPin, OUTPUT); myServo.attach(servoPin); myServo.write(0); // Start servo at 0° Serial.begin(9600); // Start Bluetooth communication } void loop() { // Check trash and servo distances float trashDistance = getDistance(trigPinTrash, echoPinTrash); float servoDistance = getDistance(trigPinServo, echoPinServo); // Trash check logic if (trashDistance = messageInterval) { if (!isServoOpen) { Serial.println("The Recycling Bin is Full"); } lastMessageTime = millis(); } } else { isTrashFull = false; } // Servo control logic if (servoDistance = openDura
Prompts
Prompts kopieren
#include Servo myServo;
// Pins
const int trigPinTrash = 7; // Trigger pin of ultrasonic sensor for trash
const int echoPinTrash = 6; // Echo pin of ultrasonic sensor for trash
const int trigPinServo = 4; // Trigger pin of ultrasonic sensor for servo
const int echoPinServo = 5; // Echo pin of ultrasonic sensor for servo
const int servoPin = 9; // Servo control pin
const int buzzerPin = 3; // Buzzer pin
// Thresholds
const float trashThreshold = 16.0; // Threshold distance for trash in cm
const float servoThreshold = 15.0; // Threshold distance for servo in cm
// Timers
unsigned long lastMessageTime = 0; // Time for last message
unsigned long lastServoMoveTime = 0; // Last time servo moved
const unsigned long messageInterval = 5000; // Message interval for trash status
const unsigned long openDuration = 5000; // Servo open duration
// State variables
bool isServoOpen = false; // Servo open status
bool isTrashFull = false; // Trash full status
void setup() {
pinMode(trigPinTrash, OUTPUT);
pinMode(echoPinTrash, INPUT);
pinMode(trigPinServo, OUTPUT);
pinMode(echoPinServo, INPUT);
pinMode(buzzerPin, OUTPUT);
myServo.attach(servoPin);
myServo.write(0); // Start servo at 0°
Serial.begin(9600); // Start Bluetooth communication
}
void loop() {
// Check trash and servo distances
float trashDistance = getDistance(trigPinTrash, echoPinTrash);
float servoDistance = getDistance(trigPinServo, echoPinServo);
// Trash check logic
if (trashDistance = messageInterval) {
if (!isServoOpen) {
Serial.println("The Recycling Bin is Full");
}
lastMessageTime = millis();
}
} else {
isTrashFull = false;
}
// Servo control logic
if (servoDistance = openDura
Info
Checkpoint & LoRA
0 Kommentar(e)
1
0
0