Moderators: adafruit_support_bill, adafruit
#include <avr/io.h>
#include <avr/interrupt.h>
#include <LiquidCrystal.h>
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we're play
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
int ledPin = 41;
int button = 21; //interrupt 2
volatile int state = 0;
LiquidCrystal lcd(12,11,5,4,3,2); //LCD connected pins
int sensorPin = A7; //analog temp sensor input
volatile int sens =0; //increment variable for temp sensor
volatile float reading, voltage, temp;
volatile int sec=0;
volatile int sec1=0;
volatile int mn=0;
volatile int mn1=0;
volatile int hr;
volatile int hr1=0;
void setup() {
lcd.begin (20,4);
//sei();
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
pinMode(27, OUTPUT);
// sei();
Serial.begin(9600);
pinMode(button, INPUT); //BUTTON
digitalWrite(19, HIGH); // Enable pullup resistor
// if (!card.init()) { //play with 8 MHz spi (default faster!)
// //putstring_nl("Card init. failed!"); // Something went wrong, lets print out why
// //sdErrorCheck();
// return;// while(1); // then 'halt' - do nothing!
// }
// //card.partialBlockRead(true);
// {
// uint8_t part;
// for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
// if (vol.init(card, part))
// break; // we found one, lets bail
// }
// }
// // Try to open the root directory
// if (!root.openRoot(vol)) {
// //putstring_nl("Can't open root dir!"); // Something went wrong,
// return; //while(1); // then 'halt' - do nothing!
// }
cli();
TCCR3A = 0; // set entire TCCR3A register to 0
TCCR3B = 0; // same for TCCR3B
// set compare match register to desired timer count:
OCR3A = 15624;
// turn on CTC mode:
TCCR3B |= (1 << WGM32);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR3B |= (1 << CS30);
TCCR3B |= (1 << CS32);
// enable timer compare interrupt:
TIMSK3 |= (1 << OCIE3A);
// enable global interrupts:
sei();
attachInterrupt (2, talkISR, RISING); //external interrupt for talk function
//lcd.begin (20,4);
lcd.clear();
lcd.setCursor(0,0);
lcd.print (" ");
lcd.setCursor (0,0); lcd.print ("The University Of");
lcd.setCursor (5,1); lcd.print ("SHEFFIELD");
lcd.setCursor (0,3); lcd.print ("OLUWATOBI BABATUNDE"); //Designed by Oluwatobi Babatunde c2012
delay(4000);
lcd.clear(); //clears display
lcd.setCursor(0,0);
lcd.print (" ");
lcd.setCursor (3,0);
lcd.print ("24-HOUR CLOCK");
delay(1000);
lcd.setCursor (3,0);
lcd.print ("SPEAKING CLOCK");
if (card.init())
{
uint8_t part;
for (part = 0; part<5; part++)
{
if (vol.init(card, part))
break;
}
}
else return;
if (root.openRoot(vol))
{
playcomplete ("01.WAV");
}
else return;
}
//void sdErrorCheck(void)
//{
// if (!card.errorCode()) return;
// putstring("\n\rSD I/O error: ");
// Serial.print(card.errorCode(), HEX);
// putstring(", ");
// Serial.println(card.errorData(), HEX);
// while(1);
//}
void talkISR()
{
playfile ("tti.WAV");
}
void loop() {
//playcomplete ("gdmor.wav");
dispTemp();
dispTime();
}
ISR(TIMER3_COMPA_vect) //timer3 interrupt service routine
{
sens++;
sec1++;
//dispTime();
if (sens ==2)
{
sens=0;
reading = analogRead(sensorPin);
voltage = reading;
// Temperature conversion to Celsius
temp = (voltage*5.0*100.0) /1024.0; //conversion using the 5V input pin
}
if (sec1 > 9)
{
sec1=0;
sec++;
}
if (sec>1) //if seconds greater than 20 seconds.
{
sec=0;
sec1=0;
mn1++;
}
if (mn1 > 1)
{
mn1 = 0;
mn++;
}
if (mn > 2)
{
mn = 0;
hr1++;
}
if (hr1 > 1)
{
hr1=0;
hr++;
}
if (hr>2)
{
hr=0; hr1=0; mn=0; mn1=0; sec=0; sec1=0;
}
//dispTime();
}
void dispTime ()
{
lcd.setCursor (0,1);
lcd.print (" ");
lcd.setCursor (14, 1);
lcd.print (sec1);
lcd.setCursor (13, 1);
lcd.print (sec);
lcd.setCursor (12, 1);
lcd.print (":");
lcd.setCursor (11, 1);
lcd.print (mn1);
lcd.setCursor (10,1);
lcd.print (mn);
lcd.setCursor (9,1);
lcd.print (":");
lcd.setCursor (8,1);
lcd.print (hr1);
lcd.setCursor (7,1);
lcd.print (hr);
}
void dispTemp ()
{
if (temp > 100)
{
lcd.setCursor (0,3);
lcd.print (" ");
}
else {
lcd.setCursor (0,3);
//lcd.print (" ");
lcd.print("Current temp ");
lcd.print(temp);
lcd.print((char)223); //degree character
lcd.print("C");
}
delay(1000); //update every second
}
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
// do nothing while its playing
}
// now its done playing
}
void playfile(char *name) {
// see if the wave object is currently doing something
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
}
// look in the root directory and open the file
if (!f.open(root, name)) {
putstring("Couldn't open file "); Serial.print(name); return;
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl("Not a valid WAV"); return;
}
// ok time to play! start playback
wave.play();
}

Return to Arduino Shields from Adafruit
Users browsing this forum: Google [Bot], MSN [Bot] and 5 guests