#include "Robot.h"
long map(long x, long in_min, long in_max, long out_min, long out_max);
static uint16_t adc_value = 0;
//if map doesnt readily work use this or u have to find a new way to represent
long map(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
//you could do it so that if the range of 900<adc_value<1023, then light p a pattern of LEDs
int main(void) {
DDRA = 0xFF; // put PORTA into output mode
PORTA = 0; //initially 0
DDRF = 0x00; // put PORTF into input mode or DDRF = 0xFC;
//or use DDRF &= ~((1<<DDF0)|(1<<DDF1));
//PORTF = 0x01; //enable pin 0 pull-up
adc_init(); //initialise ADC to read analo
_delay_ms(20);
serial0_init(); //initialise serial subsystem
int b = 0;
while (1) // main loop
{
adc_value = adc_read(0); //A0 OR = adc_read(1); for A1
b = map(adc_value,0,1023,0,255); //0,255 repalced by temprature range of thermistor
for (int i = 0; i < 8; i++){
//Serial.print(bitRead(b, i));
if(bitRead(b, i)==1){ //read bit and represent in binary
PORTA |= (1 << i);
}
else{
PORTA &= ~(1 << i);
}
//serial0_write_byte(bitRead(b, i));
}
}
return (1);
} // end main