Untitled
unknown
plain_text
a year ago
2.1 kB
7
Indexable
#include <xc.h>
#include <libpic30.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "lcd.h"
#include "buttons.h"
#include "adc.h"
#define MAX_TIME (600)
#define MIN_POWER_LEVEL (200)
#define MIN_waga (100)
#define max_waga (1000)
volatile unsigned int current_time = 0;
volatile unsigned int waga = MIN_waga;
volatile unsigned int power_level = MIN_POWER_LEVEL; // Start with minimum power level
int is_running = 0;
int reset_requested = 0;
void update_display() {
char buffer[32];
unsigned char minutes = current_time / 60;
unsigned char seconds = current_time % 60;
sprintf(buffer, "Czas: %02u:%02u\nMoc: %dW\n", minutes, seconds, power_level);
LCD_ClearScreen();
LCD_PutString(buffer, strlen(buffer));
}
void update_display() {
char buffer[32];
sprintf(buffer, "waga: %02u\nMoc: %dW\n", waga, power_level);
LCD_ClearScreen();
LCD_PutString(buffer, strlen(buffer));
}
int main(void) {
ADC_SetConfiguration(ADC_CONFIGURATION_DEFAULT);
ADC_ChannelEnable(ADC_CHANNEL_POTENTIOMETER);
TRISA = 0x0000;
LCD_Initialize();
while(!reset_requested) {
unsigned int pot_value = (unsigned int)round(ADC_Read10bit(ADC_CHANNEL_POTENTIOMETER));
// Calculate power level based on potentiometer value
power_level = pot_value ;
if (BUTTON_IsPressed(BUTTON_S4)) {
waga += 100;
if (waga > max_waga)
waga = max_waga;
while (BUTTON_IsPressed(BUTTON_S4)){}
}
if (BUTTON_IsPressed(BUTTON_S6)) {
is_running = !is_running; // Toggle start/stop state
while (BUTTON_IsPressed(BUTTON_S6)){}
}
if (BUTTON_IsPressed(BUTTON_S3)) {
current_time = (waga + power_level)/2;
reset_requested = 1;
while (BUTTON_IsPressed(BUTTON_S3)){}
}
if (is_running && current_time > 0) {
current_time--;
}
update_display();
__delay32(2000000);
}
return 0;
}
Editor is loading...
Leave a Comment