
//arduino9

#include <DFRobot_DF2301Q.h>
#include <Wire.h>

// Instance for I2C communication
DFRobot_DF2301Q_I2C asr;

// Define the pin to control
const int targetPin = 13;
const int trashPin = 7;//output for trash to arduino 10
const int trashPin2 = 8;//output for trash to arduino 5 motor control

void setup() {
  Serial.begin(115200);
  pinMode(targetPin, OUTPUT);
  digitalWrite(targetPin, LOW); // Start with pin off

  pinMode(trashPin, OUTPUT);
  digitalWrite(trashPin, LOW);//start with pin off

  pinMode(trashPin2, OUTPUT);
  digitalWrite(trashPin2,LOW);//start with pin off

  // Initialize the sensor
  while (!asr.begin()) {
    Serial.println("Voice Module Initialization Failed!");
    delay(1000);
  }
  
  // Set volume (1-7)
  asr.setVolume(5);
  // Set wake-up duration (0-255 seconds)
  asr.setWakeTime(10);
  
  Serial.println("System Ready. Say 'Hello Zeno' to activate pin 7.");
}

void loop() {
  // Get command ID
  uint8_t CMDID = asr.getCMDID();

  // ID 2 is the default "Hello Robot" wake-up word
  if (CMDID == 5) {
    Serial.println("Come detected!");
    digitalWrite(targetPin, HIGH); // Turn pin on
    delay(1000);                   // Wait 1 second
    digitalWrite(targetPin, LOW);  // Turn pin off
  }

  if (CMDID == 6) {//trash command detected
    digitalWrite(trashPin, HIGH);//turn trash pin on
    digitalWrite(trashPin2,HIGH);
    delay(1000);
    digitalWrite(trashPin,LOW);
    digitalWrite(trashPin2, LOW);
  }

 

  
  delay(100); // Small delay to stabilize I2C
}
