No sé desde hace cuanto que el IDE Energia soporta la placa LM4F120, pero el caso es que ya lo hace!
Energia es un fork del IDE de Arduino, tiene la misma interfaz pero en vez de ser para placas de Arduino con microcontroladores Atmel, es para placas con chip de Texas Instruments, las mismas que prácticamente regalaban hace poco mas de un año y que apenas use por lo «engorroso/complejo» que eran de usar en comparación con Arduino.
Se usa igual que el IDE de Arduino, desde Tools > Boards, se puede seleccionar la placa que se quiera programar, y desde Tools > Serial Port, se elige el puerto de la placa.
Después solo queda cargar el código y darle a grabar. Con el siguiente código de ejemplo se hace un Blink RGB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
void setup() { pinMode(RED_LED, OUTPUT); pinMode(GREEN_LED, OUTPUT); pinMode(BLUE_LED, OUTPUT); } void loop() { setColor( 255, 0, 0 ); // Red setColor( 0, 255, 0 ); // Green setColor( 0, 0, 255 ); // Blue setColor( 255, 255, 0 ); // Yellow setColor( 80, 0, 80 ); // Purple setColor( 0, 255, 255 ); // Aqua } void setColor(int red, int green, int blue) { analogWrite(RED_LED, red); analogWrite(GREEN_LED, green); analogWrite(BLUE_LED, blue); delay(1000); } |
Este otro código además de cambiar el color del led RGB lo hace con efecto PWM subiendo y bajando el brillo.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
/* Fade RGB LED Smoothly through 4 colours Fades an RGB LED using PWM smoothly through 4 different colours pausing for 1.5 seconds on each colour. Connect an common Cathode RGB LED with appropriate resistors on each anode to your Arduino Uno; Red to pin 11, Green to pin 10, Blue to pin 9, Cathode to GND. Developed for Arduino Uno by Joshua David - TechHelpBlog.com Please Feel Free to adapt and use this code in your projects. Contact me at techhelpblog.com and let me know how you've used it! http://www.techhelpblog.com/2012/03/19/program-fading-colours-smoothly-pwm-rgb-led-arduino-uno/ */ // Assign LED Output PWM Pins int Red = RED_LED; int Green = GREEN_LED; int Blue = BLUE_LED; //Set Initial Values int RedVal = 0; int GreenVal = 0; int BlueVal = 0; int fade = 10; // Delay Time // Colour Value 1 as each colour intensity (0-255) int RedVal1 = 186; int GreenVal1 = 0; int BlueVal1 = 255; // Colour Value 2 int RedVal2 = 9; int GreenVal2 = 239; int BlueVal2 = 26; //Colour Value 3 int RedVal3 = 255; int GreenVal3 = 120; int BlueVal3 = 0; //Colour Value 4 int RedVal4 = 0; int GreenVal4 = 255; int BlueVal4 = 78; //Set initial mode (Colour Value Mode) to Colour Value 1 int mode = 1; void setup() { // Assign outputs pinMode( Red, OUTPUT ); pinMode( Green, OUTPUT ); pinMode( Blue, OUTPUT ); // Write Initial Values of 0 to outputs analogWrite( Red, RedVal ); analogWrite( Green, GreenVal ); analogWrite( Blue, BlueVal ); } void loop() { while( mode == 1 ) { // If RedVal is less than desired RedVal1 if( RedVal < RedVal1 ) { RedVal++; // increment RedVal } // If RedVal is more than desired RedVal1 else if( RedVal > RedVal1 ) { RedVal--; // decrement RedVal } // If RedVal is equal to desired RedVal1 else if( RedVal == RedVal1 ) { //Do Nothing } // Repeated as above for BlueVal if( BlueVal < BlueVal1 ) { BlueVal++; } else if( BlueVal > BlueVal1 ) { BlueVal--; } else if( BlueVal == BlueVal1 ) { //Do Nothing } // Repeated as above for GreenVal if( GreenVal < GreenVal1 ) { GreenVal++; } else if( GreenVal > GreenVal1 ) { GreenVal--; } else if( GreenVal == GreenVal1 ) { // Do Nothing } // Now we have a new set of values, we write them to the PWM Pins. analogWrite( Red, RedVal ); analogWrite( Green, GreenVal ); analogWrite( Blue, BlueVal ); delay( fade ); // Implement a bit of delay to slow the change of colour down a bit // If RedVal & GreenVal & BlueVal are all at the desired values if( RedVal == RedVal1 && GreenVal == GreenVal1 && BlueVal == BlueVal1 ) { delay( 1500 ); // Delay to hold this colour for a little while mode = 2; // Change the mode to the next colour. Exiting this while loop and into the next one } } while( mode == 2 ) { if( RedVal < RedVal2 ) { RedVal++; } else if( RedVal > RedVal2 ) { RedVal--; } else if( RedVal == RedVal2 ) { //Do Nothing } if( BlueVal < BlueVal2 ) { BlueVal++; } else if( BlueVal > BlueVal2 ) { BlueVal--; } else if( BlueVal == BlueVal2 ) { //Do Nothing } if( GreenVal < GreenVal2 ) { GreenVal++; } else if( GreenVal > GreenVal2 ) { GreenVal--; } else if( GreenVal == GreenVal2 ) { // Do Nothing } analogWrite( Red, RedVal ); analogWrite( Green, GreenVal ); analogWrite( Blue, BlueVal ); delay( fade ); if( RedVal == RedVal2 && GreenVal == GreenVal2 && BlueVal == BlueVal2 ) { delay( 1500 ); mode = 3; //break; } } while( mode == 3 ) { if( RedVal < RedVal3 ) { RedVal++; } else if( RedVal > RedVal3 ) { RedVal--; } else if( RedVal == RedVal3 ) { //Do Nothing } if( BlueVal < BlueVal3 ) { BlueVal++; } else if( BlueVal > BlueVal3 ) { BlueVal--; } else if( BlueVal == BlueVal3 ) { //Do Nothing } if( GreenVal < GreenVal3 ) { GreenVal++; } else if( GreenVal > GreenVal3 ) { GreenVal--; } else if( GreenVal == GreenVal3 ) { // Do Nothing } analogWrite( Red, RedVal ); analogWrite( Green, GreenVal ); analogWrite( Blue, BlueVal ); delay( fade ); if( RedVal == RedVal3 && GreenVal == GreenVal3 && BlueVal == BlueVal3 ) { delay( 1500 ); mode = 4; //break; } } while( mode == 4 ) { if( RedVal < RedVal4 ) { RedVal++; } else if( RedVal > RedVal4 ) { RedVal--; } else if( RedVal == RedVal4 ) { //Do Nothing } if( BlueVal < BlueVal4 ) { BlueVal++; } else if( BlueVal > BlueVal4 ) { BlueVal--; } else if( BlueVal == BlueVal4 ) { //Do Nothing } if( GreenVal < GreenVal4 ) { GreenVal++; } else if( GreenVal > GreenVal4 ) { GreenVal--; } else if( GreenVal == GreenVal4 ) { // Do Nothing } analogWrite( Red, RedVal ); analogWrite( Green, GreenVal ); analogWrite( Blue, BlueVal ); delay( fade ); if( RedVal == RedVal4 && GreenVal == GreenVal4 && BlueVal == BlueVal4 ) { delay( 1500 ); mode = 1; // Set mode back to 1 to return to the original colour. //break; } } } |