Wednesday 8 December 2010

/hmm the clicker method doesnt work as it speaks both sentences wqhen the box opens...not sure why
// set up a new serial port
//rxPin: the pin on which to receive serial data
//txPin: the pin on which to transmit serial data
#include
const int buttonPin = 5; // the number of the pushbutton pin
const int ledPin = 13;
int clicker =0;
#define txPin 2
#define rxPin 3
#define busyPin 4
int buttonState = 0;
// set up SoftwareSerial port
SoftwareSerial speakJet = SoftwareSerial(rxPin, txPin);
char helloMiki[] = {
20, 96, 21, 114, 22, 88, 23, 5, 183, 7, 159, 146, 164, 6,6, 6, 140, 129, 194, 129};
char sounds[] = {
200, 201, 202, 203, 220, 221, 222};
char message[] = {
20, 96, 21, 114, 22, 88, 23, 5, 8, 135, 8, 146, 5, 128, 153, 5, 170, 154, 8, 188, 5, 152, 5, 170, 8,128,146,8,135,8,144,5,8,191,162,5,8,134,187};
char one[] = {
147, 142, 6};//'one'
char two[] ={
191, 162, 6};
char hbrock[] ={
159, 146, 164, 6, 171,148,135, 194};



void setup()
{
// initialize the serial communications with PC:
Serial.begin(9600);
// define pin modes for tx, rx pins:
//pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
speakJet.begin(9600);
}

void SJBusy(){
delay(20); // wait 12ms minimum before checking SpeakJet busy pin
while(digitalRead(busyPin)){
delay(250); // wait here while SpeakJet is busy (pin 4 is true)
}
delay(250); // a bit more delay is needed for some reason
}

void loop() {
buttonState = digitalRead(buttonPin);

// if it is, the buttonState is LOW:
if (buttonState == LOW) {
// turn LED on:
clicker++;
Serial.println(clicker);
// speakJet.print(sounds);
// speakJet.print(message);
// speakJet.print(helloMiki);

digitalWrite(ledPin, HIGH);

}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}

// buttonRead2(clicker);
SJBusy();
buttonRead(clicker);
buttonRead2(clicker);
}


void buttonRead(int c){
if((buttonState ==LOW)&&(clicker<=4)){

// your hand is on the sensor
speakJet.print(hbrock);
}
}

void buttonRead2(int c){


if((c>4)&& (buttonState ==LOW)){
speakJet.print(sounds);
}
}



No comments:

Post a Comment