Bu videoda EEPROM’un ne olduğunu ve Arduino’da EEPROM kullanımını detaylı olarak inceliyorum.
Videoda kullanılan Arduino sketch koduna aşağıdan ulaşabilirsiniz:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
/* Arduino Uno RGB EEPROM U8G2 ekran kütüphanesi ile çalışır. METE HOCA, Şubat 2024 WS: www.metehoca.com YT: www.youtube.com/MeteHoca IG: www.instagram.com/metehoca */ #include <Wire.h> #include <U8g2lib.h> #include <EEPROM.h> U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // SSD1306 0.96" I2C OLED //U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // SH1106 1.3" I2C OLED #define SagaYasla(x) (128-u8g2.getUTF8Width(x)) unsigned long previousMillis = 0; byte menu = 1; bool bekle_red = 0; bool bekle_green = 0; bool bekle_blue = 0; byte red, green, blue; byte pot = A2; byte btn_kaydet = 2; byte btn_menu = 3; byte led_kaydet = 13; byte led_red = 9; byte led_green = 10; byte led_blue = 11; void setup() { u8g2.begin(); u8g2.setFontPosTop(); pinMode(pot, INPUT); pinMode(btn_kaydet, INPUT); pinMode(btn_menu, INPUT); pinMode(led_red, OUTPUT); pinMode(led_green, OUTPUT); pinMode(led_blue, OUTPUT); pinMode(led_kaydet, OUTPUT); red = EEPROM.read(0); green = EEPROM.read(1); blue = EEPROM.read(2); attachInterrupt(digitalPinToInterrupt(btn_kaydet), KAYDET_Debounce, FALLING); attachInterrupt(digitalPinToInterrupt(btn_menu), MENU_Debounce, FALLING); } void loop() { u8g2.clearBuffer(); u8g2.setFont(u8g2_font_6x10_tr); u8g2.drawStr(3, 2, "METE HOCA RGB EEPROM"); u8g2.setFont(u8g2_font_courB14_tr); int adc = 0; for (byte x = 0; x < 20; x++) { adc = adc + analogRead(pot)/4; delay(1); } adc = adc / 20; if (menu == 1) { if (bekle_red == 0) {if (adc < (red - 5) || adc > (red + 5)) bekle_red = 0; else bekle_red = 1;} else red = adc; u8g2.drawStr(80, 18, ">"); u8g2.drawStr(80, 34, " "); u8g2.drawStr(80, 50, " "); } else bekle_red = 0; if (menu == 2) { if (bekle_green == 0) {if (adc < (green - 5) || adc > (green + 5)) bekle_green = 0; else bekle_green = 1;} else green = adc; u8g2.drawStr(80, 18, " "); u8g2.drawStr(80, 34, ">"); u8g2.drawStr(80, 50, " "); } else bekle_green = 0; if (menu == 3) { if (bekle_blue == 0) {if (adc < (blue - 5) || adc > (blue + 5)) bekle_blue = 0; else bekle_blue = 1;} else blue = adc; u8g2.drawStr(80, 18, " "); u8g2.drawStr(80, 34, " "); u8g2.drawStr(80, 50, ">"); } else bekle_blue = 0; u8g2.drawStr(0, 18, "RED : "); u8g2.setCursor(SagaYasla(String(red).c_str()), 18); u8g2.print(red); u8g2.drawStr(0, 34, "GREEN : "); u8g2.setCursor(SagaYasla(String(green).c_str()), 34); u8g2.print(green); u8g2.drawStr(0, 50, "BLUE : "); u8g2.setCursor(SagaYasla(String(blue).c_str()), 50); u8g2.print(blue); analogWrite(led_red, red); analogWrite(led_green, green); analogWrite(led_blue, blue); u8g2.sendBuffer(); } void KAYDET() { digitalWrite(led_kaydet, HIGH); delay(200); digitalWrite(led_kaydet, LOW); EEPROM.update(0, red); EEPROM.update(1, green); EEPROM.update(2, blue); } void MENU() { menu++; if (menu == 4) menu = 1; } void KAYDET_Debounce() { static unsigned long last_interrupt_time = 0; unsigned long interrupt_time = millis(); if (interrupt_time - last_interrupt_time > 170) KAYDET(); last_interrupt_time = interrupt_time; } void MENU_Debounce() { static unsigned long last_interrupt_time1 = 0; unsigned long interrupt_time1 = millis(); if (interrupt_time1 - last_interrupt_time1 > 170) MENU(); last_interrupt_time1 = interrupt_time1; } |