I am trying to send integers from 0 to 255 to my Atmega8L AVR, and use that value as PWM and light up a LED for each pin (3 pins)...
I am doing this in Java (Android) to send data to my AVR via USART:
byte toSend[] = {(byte)intA, (byte)intB, (byte)intC};
bleService.writeMLDP(toSend); //sends data to AVR (byte[] or String, it's working fine)
In my AVR code I have the following:
int i = 0, filled_all = 0;
char bytes[3];
//ISR is called everytime data is received
ISR( USART_RXC_vect ) {
bytes[i] = UDR; //UDR is the data received
i++;
if(i == 3) filled_all = 1;
if(filled_all == 1) {
OCR1A = bytes[0]; //sets 1st PWM
OCR1B = bytes[1]; //sets 2nd PWM
OCR2 = bytes[2]; //sets 3rd PWM
i = 0;
filled_all = 0;
}
}
There is a lot of problems:
- All LEDs are starting on full-power (it's not inverted and I'm setting it to 0x00 at the start of my "main()";
- I have to send data twice to change the LEDs' power;
- 1st and 2nd pins are inverted (as if data is being sent like toSend[1] -> toSend[0] -> toSend[2]).