I bought Spakfun Inventors Kit V3.2
This is my sketch:
//…
//Written By: Francisco J. Gonzalez Holmann
// 3:00pm , 03/04/2015
//Semana Santa - Viernes
//…
#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3); // RX, TX
const int PinUno = 3; //digital
const int PinDos = 4; //digital
const int Temp = 1; //Analog
float voltage, degreesC, degreesF;
const int buzzer = 9; //digital
const int songLength = 18;
char notes = "cdfda ag cdfdg gf ";
int beats = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
int tempo = 150;
void setup() {
XBee.begin(9600);
pinMode(PinUno, OUTPUT);
pinMode(PinDos, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
if (XBee.available()) {
int inByte = XBee.read();
switch (inByte) {
case ‘5’:
digitalWrite(PinDos, HIGH);
break;
case ‘6’:
digitalWrite(PinDos, LOW);
break;
case ‘7’:
digitalWrite(PinUno, HIGH);
break;
case ‘8’:
digitalWrite(PinUno, LOW);
break;
case ‘1’:
voltage = analogRead(Temp) * 0.004882814;
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0/5.0) + 32.0;
XBee.print("Holmann Voltage: ");
XBee.print(voltage);
XBee.print(" Grados C: ");
XBee.print(degreesC);
XBee.print(" Grados F: ");
XBee.println(degreesF);
break;
case ‘2’:
int i, duration;
for (i = 0; i < songLength; i++) {
duration = beats * tempo;
if (notes == ’ ') {
delay(duration);
} else {
tone(buzzer, frequency(notes), duration);
delay(duration);
}
delay(tempo/5);
}
break;
}
}
}
int frequency(char note) {
int i;
const int numNotes = 8;
char names[] = { ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’ };
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
for (i = 0; i < numNotes; i++) {
if (names == note) {
return(frequencies);
}
}
return(0);
}
When I press 5 a red led turns on (ok)
When I press 6 red led turns off (ok)
When I press 7 a relay turns a table light On (ok)
When I press 8 relay turns my table light Off (ok)
When I press 2 the buzzer plays a song (ok)
Howerver:
When I press 1 (Analog pin) I get the temperature and at the same time my
table light turns on for a milisecond and then turns off.
Any idea what is happening?.
Regards
Franco