0
\$\begingroup\$

I am trying to write a program that detects up/down and left/right gestures from a gesture sensor using atmega32a.

I can't actually read the LEDs and the sensor been used is the APDS 9900.

This is what I have so far:


#include <avr/io.h>
#define F_CPU 8000000UL
#include <avr/delay.h>
int Data_read();
int main(void)
{
    DDRB = 255;
    TWBR = 0x07;
    TWI_START();
    _delay_ms(500);
    TWI_SLAW(0x72);
    _delay_ms(500);
    TWI_SLAW(0x80);
    _delay_ms(500);
    Data_Out(69);
    _delay_ms(500);
    TWI_SLAW(0xAB);
    _delay_ms(500);
    Data_Out(1);
    _delay_ms(500);
    TWI_SLAW(0xAA);
    _delay_ms(500);
    Data_Out(0);
    _delay_ms(500);
    TWI_STOP();
    TWI_START();
    _delay_ms(5000);
    TWI_SLAW(0x72);
    _delay_ms(1000);
    TWI_SLAW(0xFC);
    _delay_ms(1000);
    _delay_ms(1000);
    int b = Data_read();
    PORTB = b;
    while (1) 
    {
    }
}

void TWI_INIT()
{
    //TWBR = 0x00;

}
void TWI_START()
{
    TWCR = (1 << TWSTA) | (1 << TWEN) | (1 << TWINT);
    while (!(TWCR & (1<< TWINT)))
    {
        PORTB = TWSR;
    }
}
void TWI_SLAW(int x)
{
    TWDR = x;
    TWCR = (1 << TWEN) | (1 << TWINT);
    while (!(TWCR & (1<< TWINT)))
    {
        PORTB = TWSR;
    }
}
void Data_Out(int y)
{
    TWDR = y;
    TWCR = (1 << TWEN) | (1 << TWINT);
    while (!(TWCR & (1<< TWINT)))
    {
        PORTB = TWSR;
    }   
}
void TWI_STOP()
{
    TWCR = (1 << TWINT) | (1 << TWSTO) | (1 << TWEN);
}
int Data_read()
{
    TWCR = (1 << TWINT) | (1 << TWEN);
    PORTB = TWSR;
    while (!(TWCR & (1<< TWINT)));
    while((TWSR & 0xF8) != 0x80);
    int x = TWDR;
    return x;

}
```
\$\endgroup\$
  • \$\begingroup\$ hi! I've touched up formatting of your post and also removed all the commented-out code. You will need to tell us much more about what it means that you "can't read LEDs"; LEDs are typically outputs, why are you reading them? How? What happens, what did you expect to happen, how's that differen? \$\endgroup\$ – Marcus Müller Oct 4 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.