Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h>
- const byte ROWS = 4;
- const byte COLS = 3;
- char hexaKeys[ROWS][COLS] = {
- {1, 2, 3},
- {4, 5, 6},
- {7, 8, 9},
- {'*', '0', '#'}
- };
- byte rowPins[ROWS] = {7, 6, 5, 4};
- byte colPins[COLS] = {3, 2, 1};
- Keypad keypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- #define BINTANG 42 // nilai BINTANG
- #define PAGAR 35 // nilai pagar
- long dtKey = 0;
- int key;
- String line1 = "";
- String line2 = "";
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- #define rel_pompa 2
- #define rel_peltier 4
- #define rel_heater 5
- int state = 0;
- #define STOP 0
- #define RUN 1
- float set_freq = 0;
- float TOP = 0;
- const unsigned long crystal = 16000000L;
- #define led 0
- unsigned long cur_time_led, old_time_led;
- bool stateLed = false;
- void setup() {
- delay(100);
- pinMode(rel_pompa, OUTPUT);
- pinMode(rel_peltier, OUTPUT);
- pinMode(rel_heater, OUTPUT);
- pinMode(led, OUTPUT);
- Serial.begin(115200);
- lcd.init();
- lcd.backlight();
- init_freq();
- Serial.println("system mulai");
- }
- void loop() {
- key = keypad.getKey();
- if (key) {
- baca_key(); lcd.clear(); delay(20);
- }
- update_lcd();
- control();
- }
- void baca_key() {
- switch (state) {
- case STOP:
- if ( key == 48 )key = 0;
- if ( key < 10) {
- dtKey = dtKey * 10 + key;
- //TOP = float(crystal)/((float)dtKey*64)-1;
- }
- if (key == BINTANG) {
- dtKey = 0;
- set_freq = 0;
- }
- if (key == PAGAR) {
- TOP = float(crystal) / ((float)dtKey * 64) - 1;
- init_freq();
- state = RUN;
- }
- break;
- case RUN:
- if (key == BINTANG) {
- state = STOP;
- }
- break;
- }
- }
- void get_text() {
- switch (state) {
- case STOP:
- line1 = "Set Freq";
- line2 = "Freq: " + String(dtKey) + " Hz";
- break;
- case RUN:
- line1 = "Running...";
- //line1 = String(TOP, 2);
- line2 = "Freq: " + String(dtKey) + " Hz";
- break;
- }
- }
- void update_lcd() {
- get_text();
- lcd.setCursor(0, 0);
- lcd.print(line1);
- lcd.setCursor(0, 1);
- lcd.print(line2);
- }
- void control() {
- switch (state) {
- case STOP:
- analogWrite(13, 0);
- break;
- case RUN:
- analogWrite(13, 1);
- break;
- }
- }
- void init_freq() {
- DDRD |= (1 << PD5);
- TCNT1 = 0;
- ICR1 = TOP;
- TCCR1A = (1 << WGM11) | (1 << COM1A1);
- TCCR1B = (1 << WGM12) | (1 << WGM13) | (1 << CS10) | (1 << CS11);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement