Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.7 kB
6
Indexable
Never
#include <LCD.h>
#include <avr/io.h>
#include <util/delay.h>
#define checkbit(x,y) ((x) & (y))
#define bitn(p) (0x01 << (p))
int main (void)
{
  LCD lcd;
  lcd.init ();
  char data;
  UCSRA = 0x00;
  UCSRB = 0x18;
  UCSRC = 0x06;
  UBRRH = 0x00;
  UBRRL = 0x67;
  while (1)
  {
    while(!(checkbit(UCSRA, bitn(RXC))));
    char recieveddata = data;
    data = UDR;
    String garbage[] = {"plastic bag", "styrofoam", "cigarette butt"};
    String recycle[] = {"aluminum can", "glass bottle", "paper"};
    String compost[] = {"banana peel", "coffee grounds", "eggshells"};
    bool found1 = false;
    bool found2 = false;
    bool found3 = false;
    for (int i = 0; i < sizeof(garbage) / sizeof(garbage[0]); i++)
    {
      for (int j = 0; j < garbage[i].length(); j++)
      {
        if (recieveddata == garbage[i][j])
        {
          found1 = true;
          break;
        }
      }
    }
    for (int i = 0; i < sizeof(recycle) / sizeof(recycle[0]); i++)
    {
      for (int j = 0; j < recycle[i].length(); j++)
      {
        if (recieveddata == recycle[i][j])
        {
          found2 = true;
          break;
        }
      }
    }
    for (int i = 0; i < sizeof(compost) / sizeof(compost[0]); i++)
    {
      for (int j = 0; j < compost[i].length(); j++)
      {
        if (recieveddata == compost[i][j])
        {
          found3 = true;
          break;
        }
      }
    }
    if (found1)
    {
      lcd.cmd(0x01);
      lcd.string ("garbage");
    }
    else if (found2)
    {
      lcd.cmd(0x01);
      lcd.string ("recycle");
    }
    else if
    {
      lcd.cmd(0x01);
      lcd.string ("compost");
    }
    else
    {
      lcd.cmd(0x01);
      lcd.string ("UH OH");
    }
  }
}
Leave a Comment