terça-feira, 10 de junho de 2014

Código-fonte: Piano.ino

#include "notes.h"
#include "mux.h"
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#include "functions.h"

#define speaker 46
#define SDPin 53

MUX mux1(9, 10, 11, A0);
MUX mux2(22, 24, 26, A1);
MUX mux3(28, 30, 32, A2);

void setup()
{
  Serial.begin(9600);
  pinMode(SDPin, OUTPUT);
  pinMode(speaker, OUTPUT);
  pinMode(13, OUTPUT);
  
  if (!SD.begin(SDPin))
  {
    while (true)
    {
      digitalWrite(13, !digitalRead(13));
      delay(1000);
    }
  }

  digitalWrite(13, HIGH);
  player.speakerPin = speaker;
  player.setVolume(4);
  player.quality(1);
}

void loop()
{
  checkEaster(mux1, mux2);
  
  mux1.shiftPorts();
  if (digitalRead(13))
    playNote(mux1);
  else
    toneNote(mux1);
  
  mux2.shiftPorts();
  if (digitalRead(13))
    playNote(mux2);
  else
    toneNote(mux2);
  
  mux3.shiftPorts();
  if (digitalRead(13))
    playNote(mux3);
  else
    toneNote(mux3);
    
  delayMicroseconds(100);
}

Nenhum comentário:

Postar um comentário