This shows you the differences between two versions of the page.
pm:prj2025:fstancu:stefania.fintina [2025/05/30 01:23] stefania.fintina [Hardware Design] |
pm:prj2025:fstancu:stefania.fintina [2025/05/30 01:33] (current) stefania.fintina [Software Design] |
||
---|---|---|---|
Line 192: | Line 192: | ||
+ | ** Notiuni din laborator ** | ||
+ | 1. **GPIO** (driver/gpio.h – pentru control pini digitali) | ||
+ | |||
+ | <code cpp>gpio_set_direction((gpio_num_t)BUTTON_FEED, GPIO_MODE_INPUT); | ||
+ | gpio_set_pull_mode((gpio_num_t)BUTTON_FEED, GPIO_PULLUP_ONLY); | ||
+ | gpio_set_direction((gpio_num_t)BUTTON_RESET, GPIO_MODE_INPUT); | ||
+ | gpio_set_pull_mode((gpio_num_t)BUTTON_RESET, GPIO_PULLUP_ONLY); | ||
+ | gpio_set_direction((gpio_num_t)BUTTON_LOG, GPIO_MODE_INPUT); | ||
+ | |||
+ | gpio_set_direction((gpio_num_t)BUZZER_PIN, GPIO_MODE_OUTPUT); | ||
+ | gpio_set_direction((gpio_num_t)VIBRATION_PIN, GPIO_MODE_INPUT); | ||
+ | |||
+ | if (!gpio_get_level((gpio_num_t)BUTTON_RESET)) { | ||
+ | resetFeed(); | ||
+ | delay(300); | ||
+ | } | ||
+ | |||
+ | if (gpio_get_level((gpio_num_t)BUTTON_LOG)) { | ||
+ | showLastLog(); | ||
+ | delay(300); | ||
+ | } | ||
+ | |||
+ | if (millis() > vibrationIgnoreUntil && !gpio_get_level((gpio_num_t)VIBRATION_PIN)) { | ||
+ | // log event | ||
+ | } </code> | ||
+ | |||
+ | |||
+ | 2. **PWM** (ESP32Servo.h – control servo motor) | ||
+ | |||
+ | <code cpp>servo.setPeriodHertz(50); | ||
+ | servo.attach(SERVO_PIN, 500, 2400); | ||
+ | servo.write(180); | ||
+ | delay(500); | ||
+ | servo.write(0);</code> | ||
+ | |||
+ | 3. **SPI** (SPI.h + SD.h – pentru cardul microSD) | ||
+ | <code cpp>#include <SPI.h> | ||
+ | #include <SD.h> | ||
+ | |||
+ | #define SD_CS 5 | ||
+ | |||
+ | if (!SD.begin(SD_CS)) Serial.println("Eroare card SD!"); | ||
+ | |||
+ | File f = SD.open("/log.txt", FILE_APPEND); | ||
+ | if (f) { | ||
+ | f.println(logEntry); | ||
+ | f.close(); | ||
+ | } | ||
+ | |||
+ | File fRead = SD.open("/log.txt"); | ||
+ | if (fRead) { | ||
+ | while (fRead.available()) { | ||
+ | lastLine = fRead.readStringUntil('\n'); | ||
+ | } | ||
+ | fRead.close(); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | 4. **I2C** (Wire.h – folosit implicit pentru RTC și OLED) | ||
+ | |||
+ | <code cpp>#include <Wire.h> | ||
+ | #include <RTClib.h> | ||
+ | #include <Adafruit_SSD1306.h> | ||
+ | |||
+ | RTC_DS3231 rtc; | ||
+ | Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); | ||
+ | |||
+ | if (!rtc.begin()) Serial.println("Eroare RTC!"); | ||
+ | if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) Serial.println("Eroare OLED!"); | ||
+ | |||
+ | DateTime now = rtc.now(); | ||
+ | display.clearDisplay(); | ||
+ | display.setCursor(...); | ||
+ | display.println(...); | ||
+ | display.display(); | ||
+ | </code> | ||
+ | |||
+ | 5. **Intreruperi** (hardware interrupt pe butonul de hranire) | ||
+ | |||
+ | <code cpp>volatile bool feedInterrupt = false; | ||
+ | |||
+ | void IRAM_ATTR onFeedInterrupt() { | ||
+ | feedInterrupt = true; | ||
+ | } | ||
+ | |||
+ | attachInterrupt(digitalPinToInterrupt(BUTTON_FEED), onFeedInterrupt, FALLING); | ||
+ | |||
+ | // in loop(): | ||
+ | noInterrupts(); | ||
+ | bool shouldFeed = feedInterrupt; | ||
+ | feedInterrupt = false; | ||
+ | interrupts(); | ||
+ | |||
+ | if (shouldFeed) { | ||
+ | feed("manuala"); | ||
+ | } | ||
+ | </code> | ||
===== Rezultate Obţinute ===== | ===== Rezultate Obţinute ===== | ||