generated from TDD-Templates/cmake_cpputest_template_avr
Added globals and function prototypes.
This commit is contained in:
parent
6847f5026c
commit
f4b4c771b1
37
src/main.c
37
src/main.c
|
@ -1,6 +1,7 @@
|
|||
#include "stdio.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <avr/eeprom.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
|
||||
|
@ -12,12 +13,27 @@
|
|||
#define LED_PIN PB5
|
||||
#define BLINK_DELAY_MS 5000
|
||||
|
||||
#define PWM_PIN1 PB0 // Pin 5 - Motor PWM 1
|
||||
#define PWM_PIN2 PB1 // Pin 6 - Motor PWM 2
|
||||
#define ADC_PIN PB3 // Pin 2 - Fader position reading
|
||||
#define BUTTON_PIN PB4 // Pin 3 - Button input
|
||||
|
||||
#define LONG_PRESS_TIME 1000 // 1 second hold
|
||||
#define SHORT_PRESS_TIME 50 // Debounce time
|
||||
|
||||
uint8_t saved_position EEMEM; // EEPROM storage for fader position
|
||||
|
||||
//#############################
|
||||
//Prototypes
|
||||
//#############################
|
||||
|
||||
void led_blink(void);
|
||||
|
||||
void setup(void);
|
||||
uint16_t readADC(void);
|
||||
void motorCoast(void);
|
||||
void motorMove(int direction);
|
||||
uint8_t readButton(void);
|
||||
|
||||
|
||||
//#############################
|
||||
|
@ -26,11 +42,26 @@ void led_blink(void);
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
led_blink();
|
||||
|
||||
|
||||
while(1) {
|
||||
uint16_t fader_pos = readADC() >> 2; // Scale 10-bit ADC to 8-bit (0-255)
|
||||
uint8_t buttonState = readButton();
|
||||
|
||||
if (buttonState == 2) { // Long press - Save position
|
||||
eeprom_update_byte(&saved_position, fader_pos);
|
||||
}
|
||||
else if (buttonState == 1) { // Short press - Move to saved position
|
||||
uint8_t target_pos = eeprom_read_byte(&saved_position);
|
||||
if (fader_pos < target_pos - 2) motorMove(1); // Move up
|
||||
else if (fader_pos > target_pos + 2) motorMove(-1); // Move down
|
||||
else motorCoast(); // Stop when reached position
|
||||
}
|
||||
else {
|
||||
motorCoast(); // Default to coast mode
|
||||
}
|
||||
|
||||
led_blink();
|
||||
_delay_ms(500);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue