P3 initial

This commit is contained in:
S170H
2023-11-22 18:25:14 +01:00
parent ec783fd3b6
commit be0247a93b
40 changed files with 2406 additions and 303 deletions

View File

@@ -0,0 +1,62 @@
/*
* P2 Pooling.c
*
* Created: 11.11.2023 21:06:54
* Author : Safak
*/
#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#include <stdbool.h>
#define LED0 PINB0
#define LED9 PINB1
#define SW1 PIND2
#define SW2 PIND3
int activeLED = LED0;
bool blinking = true;
void setupPorts() {
DDRB = 0xff; // DDRB as output
PORTB = 0x00;
DDRD = 0x00; // DDRD as input
PORTD = 0xff;
}
void isButtonPressed() {
if ( !(PIND & (1 << SW1)) ) { // SW1 is pressed
if (activeLED == LED0) { // if D0 is on
blinking = !blinking; // toggle blinking
}
else { // switch LED
PORTB = (1 << LED0);
}
activeLED = LED0;
}
else if ( !(PIND & (1 << SW2))) { // SW2 is pressed
if (activeLED == LED9) { // if D9 is on
blinking = !blinking; // toggle blinking
}
else { // switch LED
PORTB = (1 << LED9);
}
activeLED = LED9;
}
}
int main(void) {
setupPorts();
while (1) {
isButtonPressed();
if (blinking) {
PORTB ^= (1 << activeLED);
}
else {
PORTB = (1 << activeLED);
}
_delay_ms(250);
}
}