Hi i have program that change color and brightness by writing number 1-100 for brightness and 101-109 for colors.In blocks i tried many thinks but everytime i send it from app to arduino its doesnt show in serial monitor like "101" but in 1 0 1 or ASCI character can somebody help me?
AI2 has a SendBytes bluetooth block that will send a list of byte values (0-255).
Send a make a list block with your 2 values, and receive them as byte values (0-155) in your sketch.
Post your sketch and your blocks for further advice.
Do you mean this? Because it doesnt work either.
The sending part looks okay.
So let's see the receiving part, your sketch.
recieving part is
#include <Adafruit_NeoPixel.h>
#define LED_PIN 5 //PIN PRE LEDKY
#define LED_COUNT 47 //POČET LEDIEK
enum {
RAINBOW = 101,
GREEN,//102
RED,//103
BLUE,//104
WHITE,//105
YELLOW,//106
MAGENTA,//107
CYAN,//108
OFF//109
};
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
//int k;
//int val;
int currentStatus; // urcuje aktualnu farbu - hodnota prijata zo serioveho portu
String buff; // prijate byty a ulozi String
int output = 0; // pomocna premenna, ktora uchovava v sebe hodnotu pred pridelenim do hlavnej (brightness alebo currentStatus)
int brightness = 255; // jas
long hue = 0; // hodnota aktualnej farby - pre rainbow
int currentLed = 0; // sleduje poziciu LED, s ktorou sa prave pracuje
bool resetLoop = false; // uchovava informaciu, ci sa "cyklus" ma zacat od znova
void rainbow_new(int wait);
void colorWipe_new(uint32_t color, int wait);
void setup()
{
Serial.begin(9600);
/*
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
*/
strip.begin();
strip.show();
strip.setBrightness(brightness); //JAS
//colorWipe(strip.Color(0, 255, 0), 50);
}
void loop() //CYKLUS
{
while (Serial.available() > 0)
{
if (resetLoop)
{
buff = "";
currentStatus = 0;
}
//val = Serial.read(); //PREČITANIE SÉRIOVEHO MONITORU
char temp = Serial.read();
Serial.print("temp = ");
Serial.println(temp);
if (temp != 10)
{
buff += temp;
Serial.print("buff = ");
Serial.println(buff);
continue;
}
output = buff.toInt();
if (output >= 0 && output <= 100)
{
//strip.setBrightness(brightness);
brightness = output;
}
else if (output >= 101 && output <= 109)
{
currentStatus = output;
}
//currentStatus = buff.toInt();
buff = "";
Serial.print("currentStatus = ");
Serial.println(currentStatus);
}
strip.setBrightness(brightness);
switch (currentStatus)
{
case RAINBOW:
rainbow_new(20);
break;
case RED:
colorWipe_new(strip.Color(255, 0, 0), 50);
break;
case GREEN:
colorWipe_new(strip.Color(0, 255, 0), 50);
break;
case BLUE:
colorWipe_new(strip.Color(0, 0, 255), 50);
break;
case WHITE:
colorWipe_new(strip.Color(255, 255, 255), 50);
break;
case YELLOW:
colorWipe_new(strip.Color(255, 255, 0), 50);
break;
case MAGENTA:
colorWipe_new(strip.Color(255, 0, 255), 50);
break;
case CYAN:
colorWipe_new(strip.Color(0, 255, 255), 50);
break;
case OFF:
colorWipe_new(strip.Color(0, 0, 0), 50);
break;
default:
break;
}
}
void rainbow_new(int wait) {
if ((hue >= 5 * 65536) || (resetLoop))
{
hue = 0;
}
if ((currentLed == strip.numPixels()) || (resetLoop))
{
currentLed = 0;
}
int pixelHue = hue + (currentLed / strip.numPixels());
strip.setPixelColor(currentLed, strip.gamma32(strip.ColorHSV(pixelHue)));
hue += 256;
currentLed++;
resetLoop = false;
strip.show();
delay(wait);
Serial.println(hue/5);
}
void colorWipe_new(uint32_t color, int wait) {
if ((currentLed == strip.numPixels()) || (resetLoop))
{
currentLed = 0;
}
strip.setPixelColor(currentLed, color);
resetLoop = false;
currentLed++;
strip.show();
delay(wait);
}
Try sending the light blue math number block for 102, instead of the red(purple?) text block for 102.
I am guessing that the BlueTooth SendOneByte block is sensitive to its input block type, unlike the AI2 math blocks. Its tool tip might be informative.
Let us know if that helps?