RGB LED-strip

This sketch shows how to control RGB LED-strip from Z-Uno channels of Switch Multilevel type.
  • Z-Uno board
  • Breadboard
  • RGB strip (like this)
  • 3 TIP120 NPN Power Darlington Transistor (like this)
  • 3 1.5 kΩ resistor
  • 12 V power supply unit for the RGB strip
  • 12 wires

Download Fritzing project
// demo sketch for controlling RGB-tape connected to the Z-Uno

#define REDPIN   PWM1     // pin connection R 
#define GREENPIN PWM2     // pin connection G
#define BLUEPIN  PWM3     // pin connection B
  
// set up channel
ZUNO_SETUP_CHANNELS(
      ZUNO_SWITCH_MULTILEVEL(getRed, setRed),
      ZUNO_SWITCH_MULTILEVEL(getGreen, setGreen),
      ZUNO_SWITCH_MULTILEVEL(getBlue, setBlue)
);

int levelRed;      // here wi will store for R
int levelGreen;    // here wi will store for G
int levelBlue;     // here wi will store for B

void setup() {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  Serial.begin();
  Serial.println("start");
  analogWrite(REDPIN,0);     // R switch off
  analogWrite(GREENPIN,0);   // G switch off
  analogWrite(BLUEPIN,0);    // B switch off
}
  
void loop() {
}

// getter functions

int getRed() {
  return levelRed;
}

int getGreen() {
  return levelGreen;
}

int getBlue() {
  return levelBlue;
}

// setter functions

void setRed(byte value) {
  levelRed = value;
  analogWrite(REDPIN, levelRed * 255 / 99); // set R
  Serial.print("set red = ");
  Serial.println(value);
}

void setGreen(byte value) {
  levelGreen = value;  
  analogWrite(GREENPIN, levelGreen * 255 / 99); // set G
  Serial.print("set green = ");
  Serial.println(value);
}

void setBlue(byte value) {
  levelBlue = value;  
  analogWrite(BLUEPIN, levelBlue * 255 / 99); // set B
  Serial.print("set blue = ");
  Serial.println(value);
}
Download this sketch