[Project]

Web Piano (Control Buzzer by Web)


[Items]

1. Arduino Uno
2. PHPoC Shield for Arduino (P4S-348)
3. Buzzer (Catalex Buzzer v1.0)

Click image for larger version

Name:	web_piano_items.jpg
Views:	41
Size:	23.0 KB
ID:	809


[How it works]

1. Connect PHPoC Shield for Arduino on your Arduino
2. Connect USB wireless LAN dongle to the shield for using WLAN
3. Access to the shield's web page and control your buzzer in web application


[Demo]




[Source Code]
Code:
/* arduino web server - remote control (push button) */

#include "SPI.h"
#include "Phpoc.h"

#define NOTE_C5  523
#define NOTE_D5  587
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_G5  784
#define NOTE_A5  880
#define NOTE_B5  988

PhpocServer server(80);

int Buzzer = 9;

void setup() {
  pinMode(9, OUTPUT);
  Serial.begin(9600);
  while(!Serial)
    ;

  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
  //Phpoc.begin();

  server.beginWebSocket("remote_push");

  Serial.print("WebSocket server address : ");
  Serial.println(Phpoc.localIP());  
}

void loop() {
  // wait for a new client:
  PhpocClient client = server.available();

  if (client) {
    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();

      Serial.println(thisChar);

      if(thisChar == 'A')
      {
         Serial.println("button A press");
         tone(Buzzer, NOTE_C5);
      } 
      if(thisChar == 'a') {
         Serial.println("button A release");
         noTone(Buzzer);
      }
      if(thisChar == 'B')
      {
         Serial.println("button B press");
         tone(Buzzer, NOTE_D5);
      }  
      if(thisChar == 'b') {
         Serial.println("button B release");
         noTone(Buzzer);         
      }   
      if(thisChar == 'C') {
         Serial.println("button C press");
         tone(Buzzer, NOTE_E5);
      }
      if(thisChar == 'c') {
         Serial.println("button C release");
         noTone(Buzzer);         
      }   
      if(thisChar == 'D') {
         Serial.println("button D press");        
         tone(Buzzer, NOTE_F5);
      }
      if(thisChar == 'd') {
         Serial.println("button D release");        
         noTone(Buzzer);
      }      
      if(thisChar == 'E') {
         Serial.println("button E press");
         tone(Buzzer, NOTE_G5);         
      }
      if(thisChar == 'e') {
         Serial.println("button E release");        
         noTone(Buzzer);
      }      
      if(thisChar == 'F') {
         Serial.println("button F press");
         tone(Buzzer, NOTE_A5);         
      }
      if(thisChar == 'f') {
         Serial.println("button f release");        
         noTone(Buzzer);
      }            
      if(thisChar == 'G') {
         Serial.println("button G press");
         tone(Buzzer, NOTE_B5);         
      }
      if(thisChar == 'g') {
         Serial.println("button g release");        
         noTone(Buzzer);
      }            
      if(thisChar == 'H') {
         Serial.println("button H press");
         tone(Buzzer, NOTE_C6);         
      }
      if(thisChar == 'h') {
         Serial.println("button H release");        
         noTone(Buzzer);
      }
     }
  }
}