Gyusik Song
Published © GPL3+

Web Piano (Control Buzzer by Web)

Web-based buzzer controlled with PHPoC Shield for Arduino.

IntermediateShowcase (no instructions)3 hours3,274
Web Piano (Control Buzzer by Web)

Things used in this project

Story

Read more

Code

Web_Piano.ino

C/C++
/* 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);
      }
     }
  }
}

Credits

Gyusik Song

Gyusik Song

5 projects • 9 followers

Comments