dIgitalWrite(13,HIGH); // this lights up the led! strange no?
on top of all that, my custom code here will output to serial console in the IDE (line 39) but wont output to the led on pin 13!
i am very confused by this on board led: how it works with the blink code but not with my code. if there are any wizards out there who can weigh in i seem to have hit a rut in my education. :^(
*EDIT* i think its possible that d13 led is prioritised for SD card clock (SCK) which i am attempting to use in my code. you can see this by looking at the sd card slot on the droid schematic.
Code: Select all
#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h>
#include <SPI.h> //due to a problem with the SD library, research suggest this must be included to access that library.
#define SD_ChipSelectPin 2 //we use this as a sensor to detect if sd card is present.
TMRpcm tmrpcm; //creates an object pointing at the TMRpcm library for use in this sketch.
bool loopnumber = false;
float final = 0.0;
float initial = 0.0;
float vchange = 0.0;
void setup(){
Serial.begin(9600); // allows communication with the computer at 9600 bits/S.
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("Can't detect sd card."); //check the sd card is working.
}
else {
Serial.println("Ready for action!");
}
tmrpcm.speakerPin = 28;
pinMode(13,OUTPUT); // led d13.
pinMode(24,INPUT); //pin A1.
pinMode(25,INPUT); //pin A2.
pinMode(26,INPUT); //pin A3.
pinMode(27,INPUT); //pin A4.
pinMode(28,OUTPUT); //pin A5 is the analogue audio output. analogue pins work as digital outputs.
}
void loop() {
float pinA4 = analogRead(27) * (5.0 / 1023.0);
if (!loopnumber) {
initial = pinA4;
loopnumber = true;
}
final = pinA4;
vchange = final - initial;
if (vchange >= 0.3) {
Serial.println("Button pressed. "); //LINE 39
tmrpcm.play("sound1.wav");
digitalWrite(13,HIGH); //NOT LIGHTING UP!
//delay(5000); //5 second/s before any other high level code is processed.
}
//Serial.println("loopnumber: " + (String)loopnumber + " \ pinA4 = " + (String)pinA4 + " \ vchange = " + (String)vchange);
initial = final;
}