4 rgb leds digital low issue


i have 4 common anode rgb led's. each r, g , b pin on 4 led's wired 3 pwm pins. 3 modes selected button, syncpin. code below working off arduino uno.

code: [select]
int redpin = 11; // red pin on rgb led
int bluepin = 10;   // blue pin on rgb led
int greenpin = 9;   // green pin on rgb led
int xbutton = 7;     // x button
int abutton = 6;     // button
int ybutton = 5;     // y button
int bbutton = 4;     // b button
int syncpin = a5;     // syny button, button changes modes
int counter;         // used keep track of mode
int sensorvalue;

void setup()

{
  pinmode(redpin, output);     
  pinmode(greenpin, output);   
  pinmode(bluepin, output);   
  pinmode(ybutton, output);
  pinmode(abutton, output);
  pinmode(bbutton, output);
  pinmode(xbutton, output);
  pinmode(syncpin, input);
  int counter = 1;

}

void loop()

{
  if (counter == 1)                //mode 1
 
  {
    color(0, 0, 0);
    digitalwrite(ybutton, high);        //all buttons off, no color  (off position)
    digitalwrite(xbutton, high);
    digitalwrite(bbutton, high);
    digitalwrite(abutton, high);
    delay(1);
  }
     
if (counter == 2)                    //mode 2
  {
      color(255, 255, 0);                   //set color yellow
      digitalwrite(ybutton, high);          //set y button high
      delay(1);                             // emits yellow y button 1 thousandth of second
      digitalwrite(ybutton, low);           // turn y button off
           
      color(0, 0 , 255 );                   // new color, new button on, new button off ect.
      digitalwrite(xbutton, high);
      delay(1);
      digitalwrite(xbutton, low);
           
      color(255, 0, 0);
      digitalwrite(bbutton, high);
      delay(1);
      digitalwrite(bbutton, low);
           
      color(0, 255, 0);
      digitalwrite(abutton, high);
      delay(1);
      digitalwrite(abutton, low);
  }
     
     if(counter == 3)             //mode 3
 
  {
   
    color(255,255,0);                   //set color yellow!

    digitalwrite(ybutton, high);    //all buttons on
    digitalwrite(xbutton, high);    //
    digitalwrite(bbutton, high);    //
    digitalwrite(abutton, high);    //
    delay(1);
  }

   
    int sensorvalue = analogread(syncpin);

    float voltage = sensorvalue * (5 / 1023.0);

     if(analogread(sensorvalue) < 5)
    {
      delay(200);
      counter++;
      delay(200);
    }



    if(counter > 3)        //if mode on 3, reset off or mode 1
    {
     counter = 1;
    }
   
  //end loop
}


void color(unsigned char red, unsigned char green, unsigned char blue)     // color generating function

{

  analogwrite(bluepin, 255-blue);

  analogwrite(greenpin, 255-green);

  analogwrite(redpin, 255-red);

}


the problem having part of code below(mode 2) not working when wired attiny44.

code: [select]
if (counter == 2)                    //mode 2
  {
      color(255, 255, 0);                   //set color yellow
      digitalwrite(ybutton, high);          //set y button high
      delay(1);                             // emits yellow y button 1 thousandth of second
      digitalwrite(ybutton, low);           // turn y button off
           
      color(0, 0 , 255 );                   // new color, new button on, new button off ect.
      digitalwrite(xbutton, high);
      delay(1);
      digitalwrite(xbutton, low);
           
      color(255, 0, 0);
      digitalwrite(bbutton, high);
      delay(1);
      digitalwrite(bbutton, low);
           
      color(0, 255, 0);
      digitalwrite(abutton, high);
      delay(1);
      digitalwrite(abutton, low);
  }
     


the mode 2 not working. believe not working because @ least 1 digital low given of a, b, x or y buttons. because digital low given to led or led's, if loop run once, , because loop 4 thousandths of second, skipped on delay equal 2 delays here:

code: [select]
   {
      delay(200);
      counter++;
      delay(200);
    }


which adds 400 thousandths of second. so, conclude counter incremented upwards @ end of if loop mode 2? so, not understand why digital low not working attiny44 , why if loop run once?

the other modes working fine, led's lighting beautifully, need implementing code attiny44.

thank you.

this part looks wrong:
code: [select]

    int sensorvalue = analogread(syncpin);
     if(analogread(sensorvalue) < 5) {


Arduino Forum > Using Arduino > LEDs and Multiplexing > 4 rgb leds digital low issue


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62