Teo Wei Zheng + Ho Kai Lun + Shu Peng + Fu Man
group4-2.jpg

Day 1
For thefirst day of the program, we learn some of basic networking structure and manydifferent way of making network signals stronger and more efficient. Also,there are many different types of circuit and there are many different type of antennastoo, with varying wavelength and varying signal length. We also learnt aboutthe relation between the wavelengths and the frequency of the wave. We reflectedthat although the topics were quite hard to understand, but it was stillunderstandable with the help of the trainers and the speakers.

Day 2
We learnt the basic Arduino components such as LED lights, servo motor and Piezo speaker which we experimented with. We managed to complete some examples stated in the manual. We gained a better understanding on the programming part and also assembling the wires and components on the breadboard. We also learnt to utilise the GSM for making phone calls. We learnt basic commands to make the GSM function like a normal phone and also gained a deeper understanding of how a phone works.



Day 3
We learnt more about how to connect the GSM and the Arduino together using buffer which can increase the voltage of the GSM so that it is the same voltage as the Arduino. We were also introduced to more electrical components such as LED display and learnt how to program it to display certain characters. We also had a lot of time to experiment with the Arduino and GSM.

day3-8.jpgday3-7.jpg

We managed to create some example devices such as changing the colour of the light using a rheostat and making a motor spin. We also managed to create new devices ourselves such as using a potentiometer to vary the tempo of the music played with the Piezo speaker and also to change the music played by pressing a button. Overall, we gained a deeper understanding on assembling parts into a circuit board and also gained knowledge on the programming language.

Day 4
Today, we managed to complete our product. Our product is basically a simple music player that is currently able to play and switch between two different songs, Happy Birthday and Twinkle Twinkle Little Star, with the help of two buttons.

In addition, we added something interesting to our product afterwards, which is a potientiometer that can be used to vary the speed and tone of the music. The change in speed can then be noticed in the change of lights of 8 LEDs which we added.



The specific notes for the music can then be identified. We were delighted to have completed our product and felt that it was rather cool and useful. However, we did not managed to connect and integrate the GSM module into our product right now, which we are going to figure it out tomorrow.

Our code:
//http://www.phy.mtu.edu/~suits/notefreqs.html
 
char *notes[] = {"ccggaagffeeddc", "ccdcfeccdcgfccCafedAAafgf"};
int tempo;
int **beats;
int beat1[] = {1,1,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,2,1,1,1,1,1,2};
int beat0[] = {1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2 };
 
void setMusic(){
}
 
int onOffButton = 10;
int switchButton = 11;
int speakerPin = 12;
int inputPin = 13;
 
int* beat;
int previousBulb = 0;
boolean on = true;
int currentMusic = 0;
int maxTempo = 800;
int maxRheostat = 1024;
 
void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}
 
void playNote(char note, int duration){
  char names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'A'};
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 1073  };
 
  // Play sound
  for(int i=0; i<9; i++){
    if(names[i] == note){
      int j;
      if(i == 8){
        j = 8;
      }
      else{
        j = i+2;
      }
 
      if(previousBulb != j){
        digitalWrite(previousBulb, LOW);
        digitalWrite(j, HIGH);
        previousBulb = j;
      }
 
      playTone(tones[i], duration);
    }
  }
}
 
void setup(){
  Serial.begin(9600);
 
  setMusic();
 
  //Set led as output
  for(int i=2; i<10; i++){
    pinMode(i, OUTPUT);
  }
 
  //buttons
  pinMode(onOffButton, INPUT);
  pinMode(switchButton, INPUT);
  pinMode(inputPin, INPUT);
 
  //speaker
  pinMode(speakerPin, OUTPUT);
}
 
void loop(){
  for(int i=2; i<10; i++){
    digitalWrite(i, LOW);
  }
 
  beat = beat0;
 
  while(on){
    for (int i=0; i<strlen(notes[currentMusic]); i++){
      int onOff = digitalRead(onOffButton);
      int switchMusic = digitalRead(switchButton);
      int up = digitalRead(inputPin);
      float val = (analogRead(A0)+1);
      val /= maxRheostat;
      tempo = val*maxTempo;
      Serial.println(tempo);
 
      while(!up){
        up = digitalRead(inputPin);
        //do nothing
      }
 
      if(notes[currentMusic][i] == ' '){
        delay(beat[i] * tempo);
      }
      else{
        playNote(notes[currentMusic][i], beat[i]*tempo);
      }
 
      delay(tempo/2);
 
      //Switch Music
      if(switchMusic == 0){
        currentMusic += 1;
        if(currentMusic == 2){
          currentMusic = 0;
        }
 
        if(currentMusic == 0){
          beat = beat0;
        }
        else if(currentMusic == 1){
          beat = beat1;
        }
 
        break;
        while(switchMusic == 0){
          //do nothing
          switchMusic = digitalRead(switchButton);
        }
      }
      //power off
      if(onOff == 0){
        on = false;
        break;
      }
    }
  }
 
  //power on button
  int onOff = digitalRead(onOffButton);
  if(onOff == 0){
    on = true;
    while(onOff == 0){
      onOff = digitalRead(onOffButton);
      //do nothing
    }
  }
}
 
int buttonPin = 2;
int outputPin = 3;
int up = 1;
int numbers[][7]={
  {1,1,1,0,1,1,1},
  {0,0,1,0,0,1,0},
  {1,0,1,1,1,0,1},
  {1,0,1,1,0,1,1},
  {0,1,1,1,0,1,0},
  {1,1,0,1,0,1,1},
  {1,1,0,1,1,1,1},
  {1,0,1,0,0,1,0},
  {1,1,1,1,1,1,1},
  {1,1,1,1,0,1,1},
  {0,0,0,0,0,0,0}
};
 
void setup(){
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(outputPin, OUTPUT);
 
  for(int i=0; i<7; i++){
    pinMode(i+4, OUTPUT);
  }
}
 
void loop(){
  up = digitalRead(buttonPin);
 
  for(int i=0; i<7; i++){
    digitalWrite(i+4, 0);
  }
 
  if(!up){
    for(int i=0; i<11; i++){
      for(int j=0; j<7; j++){
        digitalWrite(j+4, numbers[i][j]);
        Serial.print(j+4);
        Serial.print(' ');
        Serial.println(numbers[i][j]);
      }
      delay(1000);
    }
    up = digitalRead(buttonPin);
    while(!up){
      up = digitalRead(buttonPin);
    }
  }
}