...

First Assignment

Hiiiii, this is my first assignment of Physical cumputing course, so exciting!!!

Images

Detail image

Code

This is my coding part. lalalalal ^ 3 ^

int num = 0;
//different number to trigger different state
int buttonState = 0;
//using the num in this part to decide which states will play
int prebuttonState =0;
//reset the button


void setup() {
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  // put your setup code here, to run once:

  pinMode(2,INPUT);

  Serial.begin(9600);

}

void loop() {
  buttonState = digitalRead(2);

  if(buttonState != prebuttonState){
    //make sure only trigger once
    if(buttonState == HIGH){
      num ++;

      if(num >2){
        num = 0;
      }
      Serial.println(num);
    }
  }

  prebuttonState = buttonState;


  switch (num) {
    case 0:
      digitalWrite(9,LOW);
      digitalWrite(10,LOW);
      break;

    case 1:
      digitalWrite(9,HIGH);
      digitalWrite(10,LOW);
      break;

    case 2:
      digitalWrite(9,HIGH);
      digitalWrite(10,HIGH);
      break;
  }
  // put your main code here, to run repeatedly:
  delay(10);
}

Video

This is my video. ^ ~ ^