IMG_6316.JPG

itp

Machine Learning For Web: Sound Classifier + Teachable Machine

 

For this week’s homework, I decided to take the work I did with Cameron and Atharva in class a step further and added LEDs, so that instead of merely changing an ellipse on the screen, I could change LEDs in real time with my voice..

Here was the original code for the sound classifier.

Here is the modified code that works with LEDs.

Below is the Arduino IDE code:

int ledRed = 13;
int ledYell = 12;
int ledBlue =8;
void setup() {
  pinMode(ledRed, OUTPUT);  // sets the pin as output
  pinMode(ledYell, OUTPUT);
  pinMode(ledBlue, OUTPUT);
  Serial.begin(9600);           // initialize serial communications
  
}
 
void loop() {
 if (Serial.available() > 0) { // if there's serial data available
   int inByte = Serial.read();// read it
   Serial.write(inByte); // send it back out as raw binary data
    if (inByte == 1) {   
     digitalWrite(ledRed, HIGH); 
   delay(1000);                // waits for 2 seconds
   digitalWrite(ledRed, LOW);  // sets the LED off 
 }
else if (inByte == 2) {   
     digitalWrite(ledYell, HIGH); 
   delay(1000);                // waits for 2 seconds
   digitalWrite(ledYell, LOW);  // sets the LED off 
 }
 else if (inByte == 3) {   
     digitalWrite(ledBlue, HIGH); 
//   analogWrite(ledPin, inByte);       // use it to set the LED brightness
   delay(1000);                // waits for 2 seconds
   digitalWrite(ledBlue, LOW);  // sets the LED off 
 }
 }
}
 
Caroline NeelComment