/*
 * Start.cpp
 * Created: 2025
 *
 * Pindescription Arduino Nano
 * No.	Func.	PIN-MC	Used as In/Out Res. Pindefinition
 * D0	RX		PD0		RX			In
 * D1	TX		PD1		TX			In
 * D2	INT0	PD2		US-Echo_L	In
 * D3	INT1	PD3		US-Echo_R	In
 * D4	Digit	PD4		US-Trigger_L Out
 * D5	OC0B	PD5		PWM-B		Out
 * D6	OC0A	PD6		PWM-A		Out
 * D7	Digit	PD7		US-Trigger_R Out	->	DDRD = 0b11110000
 * D8	Digit	PB0		Motor-B		Out
 * D9	Digit	PB1		Motor-A		Out
 *D10	Digit	PB2		LS_LED		Out
 *D11	Unused	PB3					Out
 *D12	Unused	PB4					Out
 *D13	LED		PB5		LED			Out	->	DDRB = 0b11111111
 *A0	Ana		PC0		Line-L3		In
 *A1	Ana		PC1		Line-L2		In
 *A2	Ana		PC2		Line-L1		In
 *A3	Ana		PC3		Line-L0		In
 *A4	Ana		PC4		Line-R0		In
 *A5	Ana		PC5		Line-R1		In	->	DDRC = 0b00000000
 *A6	Ana		ADC6	Line-R2		In
 *A7	Ana		ADC7	Line-R3		In
 */

#define F_CPU 16000000UL //16MHz required for delay
#include <avr/io.h> //Input/Output library
#include <util/delay.h> //Needed for using _delay_...
#include <avr/interrupt.h> //External and internal Interrupts

//Macros
#define	LED_ON				PORTB |= (1 << PORTB5) //Push PORTB pin 5 high (LED, pin D13 "Nano")
#define	LED_OFF				PORTB &= ~(1 << PORTB5) //~ Not Operator
#define	LED_TOGGLE			PINB |= (1<<PINB5) //Toggle Arduino Nano pin D13

//Variablen
unsigned char z; //For tests

//Funktions, declaration
void Init (void); //Initialize Microcontroller

void setup() {
  Init();
}

void loop() {
  Init(); //Initalize the MC
	//sei(); //Enable all interrupts
	cli(); //Clear all interrupts
	while (1) {
		//At Pin 5 PORTB the LED of the Arduino board is mounted (Pin D13)
		//PORTB |= (1 << PORTB5); //Push PORTB pin 5 high (LED, pin D13 "Nano")
		//PORTB &= ~(1 << PORTB5); //~ = "NOT" Operator, 1<<5 shifts the "1" five times to the left
		//A		not A
		//0		1
		//1		0
		PINB |= (1<<PINB5); //A "1" to "PIN" toggles the Pin of the PORT
	}
}

//Initialize the Microcontroller
void Init (void) {
	//Port settings (in brackets: pin of the arduino nano board, see above too)
	//0 = Input, 1 = Output
	DDRB = 0b11111111; //PortB Pin 5 to Output, LED on Arduino Nano board (D13)
}
