How to remove certain values from slider?

Hi,
I am making a project in which I have to control the brightness and switching of LEDs using Bluetooth. The problem I'm facing is that whenever I use the sliding bar for brightness, the ASCII code in the Arduino code hits and the light automatically switches. The range of my slider is from 0 to 255. I want to make it such that the slider when reaches 35 it skips to 45 and then goes all the way to 255 and when coming back skips 45 to 35 and goes to 0.
Thanks in advance

If I understand correctly, you want the values ​​from 0 to 35 to change every 1. When the slider reaches 35, should it jump immediately to 45? And from 45 to 255 again the values ​​are supposed to change every 1?

1 Like

Exactly... I am new here on MIT app inventor and was searching for a tutorial for 2 days on this but was forced to post on the forum as I couldnt find any tutorial... So can you help me with this?

1 Like

As you can read in Anke's post, the resolution of the slider is 100 points. This means that if you set the range from 0 to 100, the values will change by 1. If you set the range from 0 to 255, the values will change by 2.55. I think you will have to solve this with the slider extension, or you can create your own slider using the Canvas component.

1 Like

brigh
This is the back of my slider any idea what I should do here?

I'll prepare an example.

2 Likes
const int ledPin = 9;      // the pin that the LED is attached to

void setup() {
  // initialize the serial communication:
  Serial.begin(9600);

 pinMode(8, OUTPUT);
  pinMode(13, OUTPUT);
  
 pinMode(12, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(4, OUTPUT);
pinMode(10, OUTPUT);
pinMode(ledPin, OUTPUT);
  }
void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {
// read the most recent byte (which will be from 44 to 255):
brightness = Serial.read();
// set the brightness of the LED:
 analogWrite(10, brightness);
analogWrite(ledPin, brightness);
  }
 
  if(Serial.available()>0)
   {     
  char data= Serial.read(); // reading the data received from the bluetooth module
  switch(data)
  {
    case '!': digitalWrite(13, HIGH);break; // when a is pressed on the app on your smart phone
    case '"': digitalWrite(13, LOW);break;
        case '#': digitalWrite(8, HIGH);break;// when a is pressed on the app on your smart phone
    case '$': digitalWrite(8, LOW);break;// when d is pressed on the app on your smart phone

case '%': digitalWrite(12, HIGH);break;// when a is pressed on the app on your smart phone
case '&': digitalWrite(12, LOW);break;
case '(': digitalWrite(7, HIGH);break;// when a is pressed on the app on your smart phone
case ')': digitalWrite(7, LOW);break;// when d is pressed on the app on your smart phone
case ' ': digitalWrite(4, HIGH);break;// when a is pressed on the app on your smart phone
case '+': digitalWrite(4, LOW);break;// when d is pressed on the app on your smart phone
default : break;
    }}}

Above I have mentioned the Arduino code I am running.


At the moment I have set the slider at 44 as the max character for my ascii code is 43 but I would like to go to zero skipping the values from 35 to 45. Hope this helps u understand it better

Try it:

Canvas_slider.aia (4.9 KB)

1 Like

I see in your sketch you have 5 LEDs, that you turn on and off independently through single letter codes.

2^5 = 32, so you have 32 possible combinations of ON/OFF.

But since you are using a slider, may I assume the 5 LEDs are in a row and equal in brightness?

In that case, you would have 6 desired combinations:
00000
10000
11000
11100
11110
11111

In that case you would only need a slider with 6 outputs (1-6)
and you could use a select-item-in-list block to get a 5 letter text command to set the 5 LEDS
based on the choice made in the slider, then send the code as text.

1 Like