Hello, Ive been working on some code for an arduino controlled lightsaber. One of the members on here (Delta_G) has helped me get this bit going. What I want to do now is to activate a soundboard module everytime the led is switched on. I am unsure how to alter the code to do this, if anyone can help me I would be greatly apperchiated
Code so far:
#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"
int butPin = 2;
int ledPin = 11;
int led12v = 12;
int ledState = 0;Â // led on or off
int lastButState = LOW;
#define SFX_TX 5
#define SFX_RX 6
#define SFX_RST 4
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
void setup(){
Â
 pinMode(butPin, INPUT_PULLUP);
 pinMode(ledPin, OUTPUT);
 pinMode(led12v, OUTPUT);
ss.begin(9600);Â Â Â Â Â Â //initialize Serial connection
//buttonState = digitalRead(buttonPin);Â //read the initial state
digitalWrite(4, LOW);
 pinMode(4, OUTPUT);
 delay(10);
 pinMode(4, INPUT);
 delay(1000); // give a bit of time to 'boot up'
}
void loop(){
Â
Â
Â
 int butState = digitalRead(butPin); // read a new button state
Â
 if(butState != lastButState){ // if the state of the button has changed
  if(butState == LOW) { // and if the button is pressed
   ledState = 1 - ledState; // button was pushed, toggle the state of the led]
 Â
  }
 }
 lastButState = butState; // save the last button state
Â
 digitalWrite(ledPin, ledState); // write the state to the led
 digitalWrite(led12v, ledState); // write the state to the led **
Â
 delay(100);   //debounce time for button
}
void audio()
{
 if(ledPin == HIGH){ // and if the button is pressed
Â
 sfx.playTrack("T01  WAV");
Â
sfx.playTrack("T02LATCHWAV");
}
}
I am aware that the void audio is probably wrong (newbie at this programming :P), so if anyone can help point me in the right direction would be great.
Thanks guys