Project showcase
Senbon Zakura (團長超大聲)

Senbon Zakura (團長超大聲) © GPL3+

A tempo game with Senbon Zakura.

  • 971 views
  • 2 comments
  • 3 respects

Components and supplies

About this project

Music Spectrum:

Circuits:

We use:

  • Arduino UNO x1
  • LEDs x32
  • 7-Segment display x1
  • Buzzer x2
  • Switch (Button) x2
  • IC74HC595 (Shift Register) x6

It is a little bit hard to connect the components.

Four IC74HC595 connect to the thirty-two LEDs. The other two IC74HC595 connect to the 7-segment display. And the buzzers are put on the corner of breadboard.

We put the button on the other breadboard.

概念:

這個概念源自於音樂節奏遊戲,我們使用 Arduino 加上電子元件來實現此音樂節奏遊戲。

我們選的曲目是千本櫻,使用發光二極體來呈現音樂節奏,用蜂鳴器來產生音樂,而七段顯示器則是來顯示分數。

玩法:

當音樂播放後發光二極體會跟著音樂顯示節奏,當打擊(按按鈕)在正確節奏上就會得分,分數會顯使在七段顯示器上。

Concept:

This concept comes from the music tempo game, and we use hardware to display the game.

We selected the music (Senbon Zakura), LEDs to show the music tempo, buzzer to produce music and a seven-segment display to show your scores.

How to play the game?

When the music plays, LEDs will follow the music tempo.

You have to press the button on the correct tempo.

If you follow the tempo correctly, you will get the points and your score will be displayed on the seven-segment display.

Demo:

Arduino Final Demo

PPT:

https://drive.google.com/file/d/171SrQr_9oOZ5ICAjKwTYwuoTjwrXmia-/view?usp=sharing

https://drive.google.com/open?id=1vFtyZMW80XaqZvF7VIK3dFG8iORTO3Fj

Code

FinalArduino
#include <Tone.h>

// 接 74HC595 的第 12 支接腳
int latchPin = 9;
// 接 74HC595 的第 11 支接腳
int clockPin = 8;
// 接 74HC595 的第 14 支接腳
int dataPin = 10;
const int buzzer = 7;
const int sym = 6;
const int btn = 5;
const int Rbtn = 4;
Tone freq1;
Tone freq2;

void setup() {
  Serial.begin(250000);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(btn,INPUT);
  pinMode(Rbtn,INPUT);
  freq1.begin(buzzer);
  freq2.begin(sym);
}
const int toneTable[]={
  131,
  147,
  165,
  175,
  196,
  220,
  247,
  0,
  264,
  294,
  330,
  349,
  392,
  440,
  494,
  0,
  524,
  588,
  660,
  698,
  784,
  880,
  932
};
char toneName[]="cdefgabNCDEFGAB";

char MainTone[]="NNNNNNNNNNNNNNNCCCCbbbbaaaagggNggaaeeddeeeeeeeNeeggaaaaDDDDbbbbCCCCbbggaaaaaaaaCCCCbbbbaaaagggNggaaeeddeeeNeeggaNaaaNaaCCCCDDDDbbbbbbbbbbbNaaCCDDNDDNENEEEEENEEGGAAEEDDEEEEaaCCDDNDDNENEEEEENEEFFEEDDCNCCCCaaCCDDNDDNENEEEEENEEGGAAEEDDEEEEaaCCFFFFEEEEDDDDCCCCDDEEbbggaaaNaaCCDDNDDDENEEEEENEEGGAAEEDDEEEEaaCCDDNDDNENEEEEENEEFFEEDDCNCCCCaaCCDDNDDNENEEEEENEEGGAAEEDDEEEEaaCCFFFFEEEEDDDDCCCCDDCCEEGGAAAAAAAA";

char  SymTone[]="NNNNNNNNNNNNNNNffNNffNNffNNffNNCCNNCCNNCCNNCCNNffNNffNNggNNggNNaNaaggaaDDCCbbfNffNNffNNffNNffNNCCNNCCNNCCNNCCNNDNDNNNDNDNNNEEDDEENNENEENNNNNNNNaaNgaagNfNffCCffggDDGGDDccggCCggaaNgaagNfNffCCffggDDGGDDccggCCggaaNgaagNfNffCCffggDDGGDDccggCCggffNfffFNeebbEEbbffFFggGGaNagaaCCaaNgaagNfNffCCffggDDGGDDccggCCggaaNgaagNfNffCCffggDDGGDDccggCCggaaNgaagNfNffCCffggDDGGDDccggCCggffNfNfFNeebbEEbbffFFggGGaaNNaaaa";

int getTone(char symbol,int pos) {
    int toneNo = 0;
    for ( int ii=0; ii<15; ii++ ) {
        if ( toneName[ii]==symbol ) {
            toneNo = ii;
            break;
        }
    }
    return toneNo+pos;
}

uint8_t L[] = {1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

byte sevenNumber [] = {
  254,//0
  48,//1
  109,//2
  121,//3
  51,//4
  91,//5
  95,//6
  114,//7
  255,//8
  123,//9
  0,//NULL
};
int number;
int SevenCounter = 0;
int MusicCounter = 0;
int PlayCounter = 0;
int TempleCounter = 0;
int BtnCounter = -50;
int numberTen;
int numberZero;
const int Musicdelay = 100;
int MaintoneNo, SymtoneNo;
bool trigger = false;
bool Rtrigger = false;
uint16_t Ldis = 0;
uint16_t Rdis = 0;

void loop() 
{ 
  int score = 0;  

  for(int i=0;i<sizeof(L)*Musicdelay;i++){    
    if(PlayCounter == sizeof(L)) PlayCounter = 0;
    if(PlayCounter == 0) score = 0;
    if(MusicCounter < Musicdelay){
      MusicCounter++;
    }
    else if(MusicCounter == Musicdelay){
      
        Ldis = Ldis << 1;
        Rdis = Rdis << 1;
        Ldis += L[PlayCounter];
        Rdis += R[PlayCounter];
        number = score;
        if(SevenCounter <10){
          numberTen =10;
          numberZero = score/100;
        }
        else if(SevenCounter <40){
          numberTen = (number-100*(score/100))/10;
          numberZero = number-10*(score/10);
        }
        else if(SevenCounter == 40){
          SevenCounter = -1;
        }
        SevenCounter++;
        MaintoneNo = getTone(MainTone[PlayCounter],8);
        SymtoneNo = getTone(SymTone[PlayCounter],0);
        freq1.play(toneTable[MaintoneNo]);
        freq2.play(toneTable[SymtoneNo]);
        
        // 送資料前要先把 latchPin 拉成低電位
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, LSBFIRST, (~sevenNumber[numberZero])); 
        shiftOut(dataPin, clockPin, LSBFIRST, (~sevenNumber[numberTen]));       
        shiftOut(dataPin, clockPin, LSBFIRST, lowByte(Rdis)); 
        shiftOut(dataPin, clockPin, LSBFIRST, highByte(Rdis)); 
        shiftOut(dataPin, clockPin, LSBFIRST, lowByte(Ldis)); 
        shiftOut(dataPin, clockPin, LSBFIRST, highByte(Ldis)); 
        // 送出第一位元組給最近的 74HC595 
        // 送完資料後要把 latchPin 拉回成高電位
        digitalWrite(latchPin, HIGH);
        MusicCounter = 1;
        PlayCounter++;
    }
  int switchStatus = digitalRead(btn);
  int RswitchStatus = digitalRead(Rbtn);
  
  if(TempleCounter == sizeof(L)) TempleCounter = 0;
  if(BtnCounter<Musicdelay){
      if(switchStatus==1){
        trigger = true;
      }
      else {
        trigger = trigger;
      }
      if(RswitchStatus==1){
        Rtrigger = true;
      }
      else {
        Rtrigger = Rtrigger;
      }
      BtnCounter++;
   }
   else if(BtnCounter == Musicdelay){      
      if(Ldis/32768==1){
        if(trigger) score++;
        else score--;
    }
    else{
      score = score;
    }
    if(Rdis/32768==1){
        if(Rtrigger) score++;
        else score--;
    }
    else{
        score = score;
    }
    if(score < 0) score = 0;
      TempleCounter++;
      BtnCounter = 1;
      trigger = false;
      Rtrigger = false;
    }
    delay(1);
  }
}

Comments

Similar projects you might like

Arduino Burglar

Project showcase by paolo_cravero

  • 2,376 views
  • 2 comments
  • 6 respects

Electronic Piano Keyboard With Preset Songs

Project tutorial by Lindsay Fox

  • 78,004 views
  • 60 comments
  • 150 respects

Rickroll Box

Project showcase by slagestee

  • 4,933 views
  • 0 comments
  • 14 respects

Buzzer Alarm System With Help Of Arduino

by Team ONYX

  • 37,915 views
  • 5 comments
  • 21 respects

Unravel Preset Piano Easy Arduino (Even a Ghoul Can Make It)

Project in progress by ExeCuteLi

  • 5,487 views
  • 8 comments
  • 20 respects

Arduino Tutorial : Mini Piano

Project tutorial by the lonely programmer

  • 6,283 views
  • 2 comments
  • 8 respects
Add projectSign up / Login