void begin(int baud)
{
/*Set baud rate */
unsigned int ubrr = 100000 / baud - 1;
UBRR0H = (unsigned char)(ubrr >> 8);
UBRR0L = (unsigned char)ubrr;
/*Enable receiver and transmitter */
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C = (1 << USBS0) | (3 << UCSZ00);
}
void print(String data)
{
for (char i : data) {
/* Wait for empty transmit buffer */
while (!(UCSR0A & (1 << UDRE0)))
;
/* Put data into buffer, sends the data */
UDR0 = i;
}
}
void print(char data)
{
while (!(UCSR0A & (1 << UDRE0)))
;
UDR0 = data;
}
void print(int data)
{
while (!(UCSR0A & (1 << UDRE0)))
;
UDR0 = data + 48;
}
class gpio {
public:
int pin;
gpio(int _pin) {
pin = _pin;
switch (pin) {
case 0: DDRD |= (1 << PD0); break;
case 1: DDRD |= (1 << PD1); break;
case 2: DDRD |= (1 << PD2); break;
case 3: DDRD |= (1 << PD3); break;
case 4: DDRD |= (1 << PD4); break;
case 5: DDRD |= (1 << PD5); break;
case 6: DDRD |= (1 << PD6); break;
case 7: DDRD |= (1 << PD7); break;
case 8 : DDRB |= (1 << PB0); break;
case 9 : DDRB |= (1 << PB1); break;
case 10: DDRB |= (1 << PB2); break;
case 11: DDRB |= (1 << PB3); break;
case 12: DDRB |= (1 << PB4); break;
case 13: DDRB |= (1 << PB5); break;
case 14: DDRC |= (1 << PC0); break;
case 15: DDRC |= (1 << PC1); break;
case 16: DDRC |= (1 << PC2); break;
case 17: DDRC |= (1 << PC3); break;
case 18: DDRC |= (1 << PC4); break;
case 19: DDRC |= (1 << PC5); break;
};
}
void on() {
switch (pin) {
case 0: PORTD |= (1 << PD0); break;
case 1: PORTD |= (1 << PD1); break;
case 2: PORTD |= (1 << PD2); break;
case 3: PORTD |= (1 << PD3); break;
case 4: PORTD |= (1 << PD4); break;
case 5: PORTD |= (1 << PD5); break;
case 6: PORTD |= (1 << PD6); break;
case 7: PORTD |= (1 << PD7); break;
case 8 : PORTB |= (1 << PB0); break;
case 9 : PORTB |= (1 << PB1); break;
case 10: PORTB |= (1 << PB2); break;
case 11: PORTB |= (1 << PB3); break;
case 12: PORTB |= (1 << PB4); break;
case 13: PORTB |= (1 << PB5); break;
case 14: PORTC |= (1 << PC0); break;
case 15: PORTC |= (1 << PC1); break;
case 16: PORTC |= (1 << PC2); break;
case 17: PORTC |= (1 << PC3); break;
case 18: PORTC |= (1 << PC4); break;
case 19: PORTC |= (1 << PC5); break;
};
}
void off() {
switch (pin) {
case 0: PORTD &= ~(1 << PD0); break;
case 1: PORTD &= ~(1 << PD1); break;
case 2: PORTD &= ~(1 << PD2); break;
case 3: PORTD &= ~(1 << PD3); break;
case 4: PORTD &= ~(1 << PD4); break;
case 5: PORTD &= ~(1 << PD5); break;
case 6: PORTD &= ~(1 << PD6); break;
case 7: PORTD &= ~(1 << PD7); break;
case 8 : PORTB &= ~(1 << PB0); break;
case 9 : PORTB &= ~(1 << PB1); break;
case 10: PORTB &= ~(1 << PB2); break;
case 11: PORTB &= ~(1 << PB3); break;
case 12: PORTB &= ~(1 << PB4); break;
case 13: PORTB &= ~(1 << PB5); break;
case 14: PORTC &= ~(1 << PC0); break;
case 15: PORTC &= ~(1 << PC1); break;
case 16: PORTC &= ~(1 << PC2); break;
case 17: PORTC &= ~(1 << PC3); break;
case 18: PORTC &= ~(1 << PC4); break;
case 19: PORTC &= ~(1 << PC5); break;
};
}
};
gpio led(13);
void setup() {
//led.on();
//delay(1000);
//led.off();
}
void loop() {
led.on();
delay(200);
led.off();
delay(200);
}