Adds

24 June 2015

RGB LED that changes colour every 0.1s - you can set the colours, order and duration

Basic code to create a flashing RGB LED that changes colour.


Please let me know if you experience any problems with this code. Be sure to check back for more Arduino code.

Schematic:




Code:


 /*  
   
 Oliver Holden  
 Created 28/10/2014  
   
 Components:  
 * Arduino UNO  
 * RGB LED  
 * 3x 220 ohm resistors  
   
 - RGB changes colour every 0.1s  
   
 Schematic for this project is on  
 http://breadboarder.blogspot.co.uk/  
   
 */  
   
 int redPin = 11;   // Red LED,  connected to digital pin 11  
 int grnPin = 10;   // Green LED, connected to digital pin 10  
 int bluPin = 9;   // Blue LED, connected to digital pin 9  
   
    
 void setup()  
 {  
  pinMode(redPin, OUTPUT);   // Setting LED pins as outputs  
  pinMode(grnPin, OUTPUT);  
  pinMode(bluPin, OUTPUT);   
 }  
    
 void loop()  
 {  
  setColor(255, 0, 0); // red   // Going through different colours  
  delay(100);           // Each colour is on for 100ms  
  setColor(0, 255, 0); // green  
  delay(100);  
  setColor(0, 0, 255); // blue  
  delay(100);  
  setColor(255, 255, 0); // yellow  
  delay(100);   
  setColor(80, 0, 80); // purple  
  delay(100);  
  setColor(0, 255, 255); // aqua  
  delay(100);  
 }  
    
 void setColor(int red, int green, int blue)   // Setting colours  
 {  
  analogWrite(redPin, red);  
  analogWrite(grnPin, green);  
  analogWrite(bluPin, blue);   
 }  

No comments:

Post a Comment