/*
* File: LightSensorExplorationMain.c
* Author: COSMOS
*
* Created on July 17, 2018, 11:27 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include "serial.h"
#include "BOARD.h"
#include "roach.h"
#include "timers.h"
/*
*
*/
#define THRESHOLD 512 //Figure out a better threshold
int main(int argc, char** argv) {
SERIAL_Init();
BOARD_Init();
Roach_Init();
TIMERS_Init();
while (1) {
if (Roach_LightLevel() > THRESHOLD) {
Roach_LEDSSet(0b111100000000);
//Your code here
} else {
//Your code here
Roach_LEDSSet(0b000000001111);
}
/*while (1) {
int NumOfSwitches;
NumOfSwitches = (1023 - Roach_LightLevel()) / 85;
int BinaryNum = 0b000000000000;
while (NumOfSwitches > 0) {
BinaryNum *= 2;
BinaryNum++;
NumOfSwitches--;
}
Roach_LEDSSet(BinaryNum);*/
/* while (1) {
//read, display light level:
LightLevel = Roach_LightLevel();
if (LightLevel < 85){
Roach_LEDSSet(0b000000000001);
}
else if (LightLevel < 170){
Roach_LEDSSet(0b000000000011);
}
else if (LightLevel < 255){
Roach_LEDSSet(0b000000000111);
}
else if (LightLevel < 341){
Roach_LEDSSet(0b000000001111);
}
else if (LightLevel < 426){
Roach_LEDSSet(0b000000011111);
}
else if (LightLevel < 511){
Roach_LEDSSet(0b000000111111);
}
else if (LightLevel < 596){
Roach_LEDSSet(0b000001111111);
}
else if (LightLevel < 682){
Roach_LEDSSet(0b000011111111);
}
else if (LightLevel < 767){
Roach_LEDSSet(0b000111111111);
}
else if (LightLevel < 852){
Roach_LEDSSet(0b001111111111);
}
else if (LightLevel < 937){
Roach_LEDSSet(0b011111111111);
}
else {
Roach_LEDSSet(0b111111111111);
}
*/
//wait 0.1 second:
TIMERS_InitTimer(0, 100);
while (TIMERS_IsTimerActive(0));
}
//printf("Hello World!\r\n");
while (1);
return (EXIT_SUCCESS);
}