Change the color of a RGB strip while the RFID tag is in place.


i started week trying achieve "title" says.
thanks forum , examples other sites, got
what wanted do.

so here, thanking help, post code. hope useful someone.


description of program:

i needed serial print number corresponds tag of rfid card

(tag 1f002990bf19 stands number 1
tag 1f0017b6b04e stands number 2 , on tags)

the numbers read vvvv or unity show standby screen when "0" read
show video when "1" read
show video b when "2" read
show video c when "3" read.

when screen in standby mode   "0 in serial"   rgb strip light on cold white color.
when screen in video   "1 in serial"   rgb strip light on soft blue color
when screen in video b   "2 in serial"   rgb strip light on magenta color
when screen in video c   "3 in serial"   rgb strip light on soft green color

if place rfid tag/card on reader, depending on tag placed, leds will
change color , (vvvv or unity) play right video, , when tag removed reader, leds change cold white color , standby screen.

code here:

code: [select]
/*im using arduino uno id-12la rfid reader
 * little "sub-shield" sparkfun use rfid reader.
 * https://www.sparkfun.com/products/9963
 * tx , rx pins id-12la sparkfun "sub-shield" connected pins 2(rx), 3(tx) arduino
 * because im using softwareserial.
 *
 * pin 6 id-12la (not rfid "sub-shield" sparkfun)
 * conected pin 7 of arduino.
 *
 * pin 6 id-12la turns high when rfid tag in range of reading
 * , low when out of range.
 *
 * pins 11,10 , 9 used control rgb leds pwm
 */



#include <softwareserial.h>

softwareserial rfid(2, 3);

int pinrango = 7;
int tagenrango= 0;
int rangoprevio = 0;

int r = 11;
int g = 10;
int b = 9;

int fader = 0;
int fadeg = 0;
int fadeb = 0;

int rprevio = 0;
int gprevio = 0;
int bprevio = 0;

int retrazo = 2;
int cant = 1;

string tarjetastring;
int tarjval;
string comparar;
int leds;

int tag = 0;

void setup() {
  pinmode(r, output);
  pinmode(g, output);
  pinmode(b, output);
  pinmode(tagenrango, input);

serial.begin(9600);
rfid.begin(9600);
serial.println("0");     //i wanted start program 0
      tag = 0;           //in order display in "stanby" mode.
      leds = led_rgb(tag);  

}

void loop() {
while(rfid.available()>0){

tarjetastring = rfid.readstring();

tarjetastring.remove(13);//removes "garbage" @ end of string
tarjetastring.remove(0,1);//removes "garbage" @ beginning of string

////////////////////tag placed/////////////////////////////

comparar = tarjetastring; //saves "clean" string in *comparar* variable
 
 //serial.println(comparar); use know "clean" hex number of cards

if(comparar == "1f002990bf19"){  //
 tarjval = 1;
 serial.println(tarjval);
 leds = led_rgb(tarjval);
}

if(comparar == "11008827cd73"){
 tarjval = 2;
 serial.println(tarjval);
 leds = led_rgb(tarjval);
}

if(comparar == "1f0017b6f04e"){
 tarjval = 3;
 serial.println(tarjval);
 leds = led_rgb(tarjval);
}


} //end of while(rfid.available()>0)


tagenrango = digitalread(pinrango); //read state if tag in range
if (tagenrango != rangoprevio) {
    if (tagenrango == high) {  //if tag placed on id-12la reader
      tag = 1;
   }
      else {                  //if tag removed off id-12la reader
      serial.println("0");
      tag = 0;
      leds = led_rgb(tag);    
    }
    delay(10);
  }
  rangoprevio = tagenrango;


} //end of main program void loop()


 int led_rgb (int x){ //secundary program running rgb leds

switch (x) {
    
    case 0:             //cold white
      
      for (fader = rprevio ; fader <= 255; fader += 2*cant)
      {
      analogwrite(r, fader);
      delay(retrazo);
      }
      
       (fadeg = gprevio ; fadeg <= 255; fadeg += 2*cant)
      {
      analogwrite(g, fadeg);
      delay(retrazo);
      }
      
       (fadeb = bprevio ; fadeb <= 150; fadeb += 2*cant)
      {
      analogwrite(b, fadeb);
      delay(retrazo);
      }

      break;
////////////////////////////////////////////////////////////////////////////////////      
    case 1:            //soft blue
        
      for (fader = 255 ; fader >= 0; fader -= cant)
      {
      analogwrite(r, fader);
      delay(retrazo);
      }
      
       (fadeg = 255 ; fadeg >= 150; fadeg -= cant)
      {
      analogwrite(g, fadeg);
      delay(retrazo);
      }
      
       (fadeb = 150 ; fadeb >= 255; fadeb -= cant)
      {
      analogwrite(b, fadeb);
      delay(retrazo);
      }

      rprevio = 0;
      gprevio = 150;
      bprevio = 255;
      
      break;
/////////////////////////////////////////////////////////////////////////////////////        
    case 2:           //magenta
      
       (fader = 255 ; fader >= 255; fader -= cant)
      {
      analogwrite(r, fader);
      delay(retrazo);
      }
      
       (fadeg = 255 ; fadeg >= 20; fadeg -= cant)
      {
      analogwrite(g, fadeg);
      delay(retrazo);
      }
      
       (fadeb = 150 ; fadeb >= 150; fadeb -= cant)
      {
      analogwrite(b, fadeb);
      delay(retrazo);
      }

      rprevio = 255;
      gprevio = 20;
      bprevio = 150;
      
      break;
/////////////////////////////////////////////////////////////////////////////////////        
    case 3:           //soft green
        
      for (fader = 255 ; fader >= 100; fader -= cant)
      {
      analogwrite(r, fader);
      delay(retrazo);
      }
      
       (fadeg = 255 ; fadeg >= 255; fadeg -= cant)
      {
      analogwrite(g, fadeg);
      delay(retrazo);
      }
      
       (fadeb = 150 ; fadeb >= 15; fadeb -= cant)
      {
      analogwrite(b, fadeb);
      delay(retrazo);
      }
      
      rprevio = 100;
      gprevio = 255;
      bprevio = 15;
      
      break;

    }//end of switch (x) or case
  
 }//end of secundary program led_rgb




Arduino Forum > Topics > Interactive Art > Change the color of a RGB strip while the RFID tag is in place.


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'