Untitled
unknown
plain_text
a year ago
3.0 kB
6
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) volatile unsigned int current_time = 0; volatile unsigned int power_level = MIN_POWER_LEVEL; // Start with minimum power level int next = 1; int waga = 100; 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_waga() { char buffer[32]; sprintf(buffer, "Waga: \n%d gram\n",waga); 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) { if (BUTTON_IsPressed(BUTTON_S6) && BUTTON_IsPressed(BUTTON_S4)) { next = !next; // Toggle start/stop state while (BUTTON_IsPressed(BUTTON_S6) && BUTTON_IsPressed(BUTTON_S4)){} } if (BUTTON_IsPressed(BUTTON_S3)) { waga = waga - 100; if (waga <= 0){ waga = 100; } while (BUTTON_IsPressed(BUTTON_S3)){} } if (BUTTON_IsPressed(BUTTON_S4)) { waga = waga + 100; while (BUTTON_IsPressed(BUTTON_S4)){} } update_display_waga(); __delay32(2000000); while(!next) { 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)) { current_time += 15; if (current_time > MAX_TIME) current_time = MAX_TIME; 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)) { if(current_time >= 15){ current_time -= 15; } while (BUTTON_IsPressed(BUTTON_S3)){} } if (is_running && current_time > 0) { current_time--; } if (is_running && current_time <= 0) { next = !next; is_running = !is_running; waga = 100; } update_display(); __delay32(2000000); } } return 0; }
Editor is loading...
Leave a Comment