bowl alpha
Latest sketch and notes:
all hardware has been secured on the breadboard with my testbed arduino uno. so far concerns are back chatter — the power lines are not clean and I have isolated the main components of speaker and bluetooth transmitter/receiver on the board with some limiting resistors. my display values are unstable at startup after physical manipulation but can be returned to null after re-adjusting the connections. In particular, the pairing of the BT is reflected by an immediate 5 to 6 impedance drop on the soft pot lines, so for now, all testing begins only after pairing is complete.
the uno revision 3 should eliminate these issues as all power and ground lines are isolated on the board.
mac address for BT has been hard coded for tablet app and I have completed the bluetooth library integration in my app.
audio: currently utilizing TONE.h library for arduino to allow for software modulation of two tones simultaneously but this is not the final plan
all physical components are working without interference [other than power mentioned above]. testing has shown consistent performance over several hours.
Next Phase: will need to integrate BTLE beacon hardware and software
//when sending from serial be sure both NL and CR are on and baud rate matches
// ended up needing to use RX pin 0 and TX pin 1
// SR will be .25 seconds
// HARDWARE
#include <Timer.h>
#include <Event.h>
#include “Arduino.h”
#include <SoftwareSerial.h>
#include “DFRobotDFPlayerMini.h”
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
// VARIABLES
const int sr = 250; //worked for a very long time // sample rate in ms??
const int le = 14; //20; //2; //40; // Low end of travel
const int he = 80; //50; was great //100; // High end of travel
const int baseSV = 20; //should be 10 but 20 when things are putting it above 0 on no touch
int dir = 1; // 1 is clockwise -1 is counterclockwise
const int SENSOR_PIN = 0; //0 was working great // Pin for ribbon
const int SENSOR_PIN2 = 1; //1 was working with 0 great //pin for ribbon2
const int LED_PIN = 13; //12; // LED pin location
bool flowing = false;
bool prevFlow = false;
int prevRead = 0;
bool isPlay=false;
int myVol=24;
int curVol=0;
Timer t;
// SETUP
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(9600);
//Serial.println(“setup”);
pinMode( LED_PIN, OUTPUT );
int senseEvent = t.every(sr, sensorCheck);
myDFPlayer.begin(mySoftwareSerial);
myDFPlayer.volume(myVol); //Set volume value. From 0 to 30
myDFPlayer.enableLoopAll();
myDFPlayer.play(4);
myDFPlayer.pause();
}
// LOOP
void loop() {
t.update();
/*
if(isPlay){
myDFPlayer.volume(myVol++);
}
else {
myDFPlayer.volume(myVol–);
}
if (isPlay){
//if(myDFPlayer.readVolume()<15){
myDFPlayer.volumeUp();
//}
}
else {
if(myDFPlayer.readVolume()>0){
myDFPlayer.volumeDown();
}
}
*/
if(Serial.available()){ //LAST change was getting rid of just serial avail, but everything inside was commented
//this works to get data back from Android
//Serial.println(Serial.read());
//char valA=Serial.read();
//if (valA==’a’)
//Serial.println(“IT WAS AN A”);
}
}
// SENSORCHECK
void sensorCheck () {
int sensorVal = analogRead( SENSOR_PIN );
int sensorVal2 = analogRead( SENSOR_PIN2);
//TENU TEST AREA
Serial.print(“VAL ONE “);
Serial.println(sensorVal);
Serial.print(“VAL tWO “);
Serial.println(sensorVal2);
int sensDelta=0;
if((sensorVal>baseSV)&&(sensorVal2<baseSV)) //only hitting s1
{
sensDelta = sensorVal – prevRead;
prevRead = sensorVal;
}
if ((sensorVal2>baseSV)&&(sensorVal<baseSV)) //only hitting s2
{
sensDelta = sensorVal2 – prevRead;
prevRead = sensorVal2;
}
if ((sensorVal>baseSV) && (sensorVal2>baseSV)) { //touching both
prevRead=0;
}
//—————————————————–
sensDelta=abs(sensDelta);
if ( ( sensDelta > le ) && ( sensDelta < he ) ) {
flowing = true;
if ( (prevFlow==true) )
{
Serial.println(“T”);
digitalWrite(LED_PIN, HIGH);
tonePlay();
} else {
Serial.println(“F”);
digitalWrite(LED_PIN, LOW);
isPlay=false;
callPause();
} //end Bblock
prevFlow = flowing;
flowing = false;
}
else { //sensDelta was not in range
digitalWrite( LED_PIN, LOW );
if (prevFlow == true) { //has moved from flow to no flow
prevFlow = false;
Serial.println(“F”);
isPlay=false;
callPause();
}//end if prevFlow
}
}
// TONEPLAY
void tonePlay() {
if(!isPlay) {
isPlay=true;
myDFPlayer.volume(myVol);
curVol=myVol;
myDFPlayer.start();
}
}
// CALLPAUSE
void callPause() {
for(int i=curVol; i–; i>-1)
{
myDFPlayer.volume(–curVol);
//myDFPlayer.volumeDown();
//curVol–;
delay(10);
}
myDFPlayer.pause();
}