1.2k
In this example we will flash an RGB LED using C
Schematics
Here is a schematic and layout
Code
This example requires wiringPi to be installed – http://wiringpi.com/download-and-install/
[codesyntax lang=”c”]
#include <wiringPi.h> #include <stdio.h> #define REDLED 0 #define GREENLED 1 #define BLUELED 2 void init(void) { pinMode(REDLED, OUTPUT); pinMode(GREENLED, OUTPUT); pinMode(BLUELED, OUTPUT); digitalWrite(REDLED, 1); digitalWrite(GREENLED, 1); digitalWrite(BLUELED, 1); } void AllOff(void) { digitalWrite(REDLED, 1); digitalWrite(GREENLED, 1); digitalWrite(BLUELED, 1); } int main(void) { int i; if(wiringPiSetup() == -1) { printf("setup of wiringPi failed !"); return 1; } init(); for(i =0;i < 10; i++) { digitalWrite(REDLED, 0); delay(1000); AllOff(); delay(1000); digitalWrite(GREENLED, 0); delay(1000); AllOff(); delay(1000); digitalWrite(BLUELED, 0); delay(1000); AllOff(); delay(1000); } return 0; }
[/codesyntax]