I'm trying to use value3 from the sliderSpinCallback function as a variable inside the sliderSpeedCallback function below it. Is there a way to do this? I tried declaring the value2 and value 3 as global variables at the beginning of the program but I guess that doesn't help because it is declared as a local variable inside the function. Any help appreciated.
void sliderBall_FeedCallback(unsigned int value1) {
Ball_Feed = value1;
/* Start your code (sliderBall_FeedCallback) */
/* End your code */
analogWrite(3,value1);
}
void sliderSpinCallback(unsigned int value3) {
/* Start your code (sliderSpinCallback) */
/* End your code */
}
void sliderSpeedCallback(unsigned int value2) {
/* Start your code (sliderSpeedCallback) */
/* End your code */
analogWrite(5,value2);
analogWrite(6,value3);
}
Here is the complete sketch:
#include <RBL_nRF8001.h>
#include <SPI.h>
#include <boards.h>
#include <IOSControllerBLE.h>
#include <EEPROM.h>
#define Ball_Feed_PIN 3
#define Speed_PIN 5
#define Spin_PIN 6
#define Sweep_PIN 4
/* Start your code (defines) */
/* End your code */
/*
*
* IOSController Library initialization
*
*/
IOSControllerBLE iosController(&doWork,&doSync,&processIncomingMessages,&processOutgoingMessages,NULL,NULL);
/******* Start Global Variable for Widgets *******/
unsigned int Ball_Feed;
unsigned int Speed;
unsigned int Spin;
unsigned int value1;
unsigned int value2;
unsigned int value3;
/******* End Global Variable for Widgets *******/
void setup()
{
ble_begin();
Serial.begin(115200);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
pinMode(10,OUTPUT);
digitalWrite(10,LOW);
Ball_Feed = 0;
pinMode(Ball_Feed_PIN,OUTPUT);
analogWrite(Ball_Feed_PIN,Ball_Feed);
Speed = 0;
pinMode(Speed_PIN,OUTPUT);
analogWrite(Speed_PIN,Speed);
Spin = 0;
pinMode(Spin_PIN,OUTPUT);
analogWrite(Spin_PIN,Spin);
pinMode(Sweep_PIN,OUTPUT);
digitalWrite(Sweep_PIN,LOW);
/* Start your code (setup) */
/* End your code */
}
void loop() {
iosController.loop();
}
/**
*
*
* This function is called periodically and it is equivalent to the standard loop() function
*
*/
void doWork() {
/* Start your code (doWork) */
/* End your code */
}
/**
*
*
* This function is called when the ios device connects and needs to initialize the position of switches and knobs
*
*/
void doSync (char *variable) {
if(strcmp(variable,"Ball Feed")==0) {
sliderBall_FeedSyncCallback();
}
if(strcmp(variable,"Speed")==0) {
sliderSpeedSyncCallback();
}
if(strcmp(variable,"Spin")==0) {
sliderSpinSyncCallback();
}
if(strcmp(variable,"Sweep")==0) {
switchSweepSyncCallback();
}
/* Start your code (doSync) */
/* End your code */
}
/**
*
*
* This function is called when a new message is received from the iOS device
*
*/
void processIncomingMessages(char *variable, char *value) {
if(strcmp(variable,"Ball Feed")==0) {
sliderBall_FeedCallback(atoi(value));
}
if(strcmp(variable,"Speed")==0) {
sliderSpeedCallback(atoi(value));
}
if(strcmp(variable,"Spin")==0) {
sliderSpinCallback(atoi(value));
}
if(strcmp(variable,"Sweep")==0) {
switchSweepCallback(atoi(value));
}
/* Start your code (processIncomingMessages) */
/* End your code */
}
/**
*
*
* This function is called periodically and messages can be sent to the iOS device
*
*/
void processOutgoingMessages() {
/* Start your code (processOutgoingMessages) */
/* End your code */
}
/* Widgets synchronization callbacks */
void sliderBall_FeedSyncCallback() {
/* Start your code (sliderBall_FeedSyncCallback) */
//iosController.writeMessage("Ball Feed",Insert value here);
/* End your code */
iosController.writeMessage("Ball Feed",Ball_Feed);
}
void sliderSpeedSyncCallback() {
/* Start your code (sliderSpeedSyncCallback) */
//iosController.writeMessage("Speed",Insert value here);
/* End your code */
iosController.writeMessage("Speed",Speed);
}
void sliderSpinSyncCallback() {
/* Start your code (sliderSpinSyncCallback) */
//iosController.writeMessage("Spin",Insert value here);
/* End your code */
iosController.writeMessage("Spin",Spin);
}
void switchSweepSyncCallback() {
/* Start your code (switchSweepSyncCallback) */
//iosController.writeMessage("Sweep",Insert value here);
/* End your code */
iosController.writeMessage("Sweep",digitalRead(Sweep_PIN));
}
/* Widgets operations callbacks */
void sliderBall_FeedCallback(unsigned int value1) {
Ball_Feed = value1;
/* Start your code (sliderBall_FeedCallback) */
/* End your code */
analogWrite(3,value1);
}
void sliderSpinCallback(unsigned int value3) {
/* Start your code (sliderSpinCallback) */
/* End your code */
}
void sliderSpeedCallback(unsigned int value2) {
/* Start your code (sliderSpeedCallback) */
/* End your code */
analogWrite(5,value2);
analogWrite(6,value3);
}
void switchSweepCallback(boolean on) {
/* Start your code (switchSweepCallback) */
/* End your code */
digitalWrite(Sweep_PIN,on);
}
/* Analog input preprocess functions */
/**** User Functions *****/
/* Start your code (User Functions) */
/* End your code */