You are on page 1of 3

/****************************************************************************

*
* This example is controlling the RGB LED using the joystick
*
* Copyright(C) 2010, Embedded Artists AB
* All rights reserved.
*

*****************************************************************************
*/

#include "lpc17xx_pinsel.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_timer.h"

#include "joystick.h"
#include "rgb.h"
#include "oled.h"

int main (void) {

//declaro las variables


uint8_t r = 0;
uint8_t g = 0;
uint8_t b = 0;

uint8_t joy = 0;

//inicio perifericos
rgb_init();
joystick_init();
oled_init();

//limpio el display
oled_clearScreen(OLED_COLOR_BLACK);

//imprimo el menu de opciones


oled_putString(1,1, (uint8_t*)"Menu >> POS/LEDS", OLED_COLOR_WHITE,
OLED_COLOR_BLACK);
oled_putString(1,10, (uint8_t*)"Center-> G ON", OLED_COLOR_WHITE,
OLED_COLOR_BLACK);
oled_putString(1,19, (uint8_t*)" Up -> R ON", OLED_COLOR_WHITE,
OLED_COLOR_BLACK);
oled_putString(1,28, (uint8_t*)"Down -> B ON", OLED_COLOR_WHITE,
OLED_COLOR_BLACK);
oled_putString(1,37, (uint8_t*)"Left -> RGB ON", OLED_COLOR_WHITE,
OLED_COLOR_BLACK);
oled_putString(1,46, (uint8_t*)"Right -> RGB OFF", OLED_COLOR_WHITE,
OLED_COLOR_BLACK);
oled_putString(1,55, (uint8_t*)">Move to START!<", OLED_COLOR_WHITE,
OLED_COLOR_BLACK);
while(1) {

joy = joystick_read();

//condicion joystick izquierda


if ((joy & JOYSTICK_LEFT) != 0) {
oled_clearScreen(OLED_COLOR_WHITE);
oled_putString(1,37, (uint8_t*)"->LEDS RGB ON<-", OLED_COLOR_BLACK,
OLED_COLOR_WHITE);
rgb_setLeds(RGB_RED|RGB_GREEN|RGB_BLUE);
r = RGB_RED;
b = RGB_BLUE;
g = RGB_GREEN;
}

//condicion joystick derecha


if ((joy & JOYSTICK_RIGHT) != 0) {
oled_clearScreen(OLED_COLOR_WHITE);
oled_putString(1,46, (uint8_t*)"->LEDS RGB OFF<-", OLED_COLOR_BLACK,
OLED_COLOR_WHITE);
rgb_setLeds(0);
r = g = b = 0;
}

//condicion joystick arriba


if ((joy & JOYSTICK_UP) != 0) {
oled_clearScreen(OLED_COLOR_WHITE);
oled_putString(1,19, (uint8_t*)"->LED RED ON<-", OLED_COLOR_BLACK,
OLED_COLOR_WHITE);
g = b = 0;
r = RGB_RED;
rgb_setLeds(r|g|b);
}

//condicion joystick centro


if ((joy & JOYSTICK_CENTER) != 0) {
oled_clearScreen(OLED_COLOR_WHITE);
oled_putString(1,10, (uint8_t*)"->LED GREEN ON<-", OLED_COLOR_BLACK,
OLED_COLOR_WHITE);
r = b = 0;
g = RGB_GREEN;
rgb_setLeds(r|g|b);
}

//condicion joystick abajo


if ((joy & JOYSTICK_DOWN) != 0) {
oled_clearScreen(OLED_COLOR_WHITE);
oled_putString(1,28, (uint8_t*)"->LED BLUE ON<-", OLED_COLOR_BLACK,
OLED_COLOR_WHITE);
r = g = 0;
b = RGB_BLUE;
rgb_setLeds(r|g|b);
}

/* delay */
Timer0_Wait(200);
}

void check_failed(uint8_t *file, uint32_t line)


{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

/* Infinite loop */
while(1);
}

You might also like