slayder functions as a mirror

View previous topic View next topic Go down

slayder functions as a mirror

Post by naonisman on Sun Oct 02, 2016 8:48 pm

Hello! I have a problem with slayder.slayder functions as a mirror when it is in the down position (0), the LED shines at full Power, respectively when the slider is in the upper maximum position (255) - the LED is no light.
if not difficult, please tell me what to change in the code.
LED on the circuit with common +

sketch:


#define bluetooth Serial

int red = 9;       // LOW = on, HIGH = off
int green = 10;    // LOW = on, HIGH = off
int blue = 11;     // LOW = on, HIGH = off

char cmd[100];
int cmdIndex;


void exeCmd() {
 
 if( (cmd[0]=='r' || cmd[0]=='g' || cmd[0]=='b') && cmd[1]==' ' ) {
   // "r", "g", "b" are the ids for red, green and blue    
      int val = 0;
      for(int i=2; cmd[i]!=0; i++) {
        val = val*10 + (cmd[i]-'0');
      }
      // if cmd is "r 100", val will be 100        
      if(cmd[0]=='r') analogWrite(red, 255-val);
      if(cmd[0]=='g') analogWrite(green, 255-val);
      if(cmd[0]=='b') analogWrite(blue, 255-val);
 }

 
}



void setup() {
 
 delay(500); // wait for bluetooth module to start

 bluetooth.begin(9600); // Bluetooth default baud is 115200
 
 pinMode(red, OUTPUT);
 pinMode(green, OUTPUT);
 pinMode(blue, OUTPUT);
 
 digitalWrite(red, LOW);  // off
 digitalWrite(green, LOW);  // off
 digitalWrite(blue, LOW);  // off
 
 cmdIndex = 0;
}


void loop() {
 
 if(bluetooth.available()) {
   
   char c = (char)bluetooth.read();
   
   if(c=='\n') {
     cmd[cmdIndex] = 0;
     exeCmd();  // execute the command
     cmdIndex = 0; // reset the cmdIndex
   } else {      
     cmd[cmdIndex] = c;
     if(cmdIndex<99) cmdIndex++;
   }
 
   
 }
 
}


naonisman

Posts : 2
Join date : 2016-10-02

View user profile

Back to top Go down

Re: slayder functions as a mirror

Post by Admin on Mon Oct 03, 2016 2:58 pm

Hi,
just replace the "255-val" with "val".

Admin
Admin

Posts : 111
Join date : 2016-03-08

View user profile http://roboremo.makeforum.net

Back to top Go down

Re: slayder functions as a mirror

Post by naonisman on Mon Oct 03, 2016 4:09 pm

Thanks!Now all is well! Very Happy Very Happy

naonisman

Posts : 2
Join date : 2016-10-02

View user profile

Back to top Go down

Re: slayder functions as a mirror

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum