Activate a Void Function from MIT App Inventor through bluetooth

I have a plan to run a void function in the arduino from the control of MIT App through Bluetooth the problem is the value that printed cannot calling out the void function and there is a problem with the Serial.read();
#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>

#define rxPin 8
#define txPin 7

Adafruit_NeoPixel strip = Adafruit_NeoPixel (12,3,NEO_RGB + NEO_KHZ800);

SoftwareSerial mySerial(rxPin, txPin); // RX, TX
char myChar ;

void setup() {
Serial.begin(9600);
Serial.println("Goodnight moon!");

mySerial.begin(9600);
mySerial.println("Hello, world?");
pinMode(13, OUTPUT);

}

void loop(){
while(mySerial.available()){
myChar = mySerial.read();
Serial.print(myChar);
}

while(Serial.available()){
myChar = Serial.read();
mySerial.print(myChar);
}

}

void ani1(){
for(int c=0;c<12;c++){
strip.setPixelColor(c,strip.Color(255,0,0));
Serial.print(c);
strip.show();
delay(100);
}
}

void ani2(){
for(int c=11;c>=0;c--){
strip.setPixelColor(c,strip.Color(255,0,0));
Serial.print(c);
strip.show();
delay(100);
}
}

And there is my apps

Please the guidance

Hello Daniel

So much information in your Topic without really telling us what you are doing!

If you want to run a function, you need to run from the loop() on receipt of data, passing that data to the function via function parameter.

Why do you have two Serial Channels reading?

Cannot read your App Inventor Blocks!
Right-mouse in the Blocks work area and select "Download Blocks as image".

So what im trying to do is to control animation of led strip through the app inventor from the module Bluetooth. What is the problem right now is have been half way here is my updates work, but look like the led is still not turning on


#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>

#define rxPin 8
#define txPin 7

Adafruit_NeoPixel strip = Adafruit_NeoPixel (24,2,NEO_RGB + NEO_KHZ800);
SoftwareSerial mySerial(rxPin, txPin); // RX, TX
char myChar ;

// function prototypes
void ani1();
void ani2();
void ani3();
void ani4();
void ani5();

// array of function pointers
void (*animations[])() =
{
ani1,
ani2,
ani3,
ani4,
ani5
};

void setup() {
Serial.begin(9600);
Serial.println("Goodnight moon!");

mySerial.begin(9600);
mySerial.println("Hello, world?");
pinMode(13, OUTPUT);

}

void loop(){
if(mySerial.available()){
myChar = mySerial.read();
myChar -= '1';
Serial.print(myChar);
if (myChar < sizeof(animations) / sizeof(animations[0]))
{
// run the selected animation
animationsmyChar;
}
}

if(Serial.available()){
myChar = Serial.read();
myChar -= '1';
Serial.print(myChar);
if (myChar < sizeof(animations) / sizeof(animations[0]))
{
// run the selected animation
animationsmyChar;
}
}

}

void ani1(){
for(int c=0;c<24;c++){
strip.setPixelColor(c,strip.Color(255,255,255));
delay(100);
strip.show();
Serial.print(c);
}
}

void ani2(){
Serial.print("animation2");
}

void ani3(){
Serial.print("animation3");
}
void ani4(){
Serial.print("animation4");
}

void ani5(){
Serial.print("animation5");
}Preformatted text

If you are not going to help me to help you..........

There is my work updates so far it can read the function, but the led is still not turned on,

What i'm trying to do is to control led through the mit apps from bluetooth. MIT Job is to sent a value to arduino to run specific animation function.

Only use a ListPicker to send the data, send 1 or 2 or 3, ... depending on the animation you want to activate.

listpiecker

In the Arduino code you put something like this ... schematic code

if (received = 1) then void ani1 ();
if (received = 2) then void ani2 ();
if (received = 3) then void ani3 ();
...

Right, so on Button1 Click you want to send the User's selection from several Lists to an Arduino. You can't send the data the way you have.

Question: why is ListPicker2. AfterPicking sending independently of Button 1?

Change your code so that on Button1 click the List selections are used to create a string, then send the string, splitting it in the Arduino Sketch OR use a Clock Timer Block to send individual Characters.

Question: What should the animation actually do? Display the Characters one-at-a-time?

The Question 2 is an error i have fix it all based on button click, the animation is based like on void 1 to turn on led from led 1 to led 23

emm what do you mean? the mit sent number of 0 1 2 3 4 at the latest block

the below block is the update

OK. There are so many errors across your code its difficult for me to tell you what to fix :upside_down_face:

Let me just write some basic code for you to try.

okay thanks alot, but usually the value is comes out but the led is doesnt turn on

Post your Sketch here (rename it from .ino to .txt)

Here is a Project, the blocks of which you can merge into your own Project. It uses a Clock Timer to send the data to Arduino.

led.txt (1.4 KB)

OK, I have made a simple Sketch which you can try out. I can't test it here unfortunately.

If it does run but too fast, increase the Clock Timer interval in the App and the loop timer in the Sketch. The Sketch time should be about 20% faster than the App time to prevent any overlap of execution.

ledBasic.txt (971 Bytes)

Emm i have seen your file and try it, It does not work, because i do have my pin tx and rx on 7 and 8. that is why there is 2 serial which transferred the pin

Ok, just rename my Serial Calls to your Software Serial name.