PCOM – Week 09

project 2

*demo

Circuit

Testing vibrating motors

Fabrication Process

Final output

7 notes(DoReMiPaSolRaThi)

‘Twinkle Twinkle little Star’

Final

Code

const int motorPin1 = 2;
const int motorPin2 = 3;
const int motorPin3 = 5;
const int motorPin4 = 6;
const int motorPin5 = 9;
const int motorPin6 = 10;
const int motorPin7 = 11;
const int motorPin8 = 12;

int inByte = 0;

void setup() {
  Serial.begin(9600);           
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(motorPin5, OUTPUT);
  pinMode(motorPin6, OUTPUT);
  pinMode(motorPin7, OUTPUT);
  pinMode(motorPin8, OUTPUT);
}

void loop() {

  if (Serial.available() > 0) { // if there's serial data available
    inByte = Serial.read();   // read it
    Serial.write(inByte);

    if (inByte == 'D') {
      digitalWrite(motorPin1, HIGH); //vibrate
      delay(500);  // delay one second
      digitalWrite(motorPin1, LOW);  //stop vibrating
      delay(500); //wait 50 seconds.
    }

    if (inByte == 'G') {
      digitalWrite(motorPin2, HIGH); //vibrate
      delay(500);  // delay one second
      digitalWrite(motorPin2, LOW);  //stop vibrating
      delay(500);
    }//wait 50 seconds.}
    // Serial.println(motorPin);

    if (inByte == 'A') {
      digitalWrite(motorPin3, HIGH); //vibrate
      delay(500);  // delay one second
      digitalWrite(motorPin3, LOW);  //stop vibrating
      delay(500);
    }//wait 50 seconds.}

    if (inByte == 'B') {
      digitalWrite(motorPin4, HIGH); //vibrate
      delay(500);  // delay one second
      digitalWrite(motorPin4, LOW);  //stop vibrating
      delay(500);
    }//wait 50 seconds.}

    if (inByte == 'C') {
      digitalWrite(motorPin5, HIGH); //vibrate
      delay(500);  // delay one second
      digitalWrite(motorPin5, LOW);  //stop vibrating
      delay(500); //wait 50 seconds.
    }

    if (inByte == 'E') {
      digitalWrite(motorPin6, HIGH); //vibrate
      delay(500);  // delay one second
      digitalWrite(motorPin6, LOW);  //stop vibrating
      delay(500);
    }//wait 50 seconds.}

    if (inByte == 'F') {
      digitalWrite(motorPin7, HIGH); //vibrate
      delay(500);  // delay one second
      digitalWrite(motorPin7, LOW);  //stop vibrating
      delay(500); //wait 50 seconds.}
    }
        } 
}

* Working on..

When I clicked the music play button, let vibrating motors vibrate according to the song’s notes respectively not without delay.
<–millis ( ) in arduino