Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Reminder System
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2024-05-18 07:59:42
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* ring buzzer and motor every 1 minute for 5 */
- /* minutes. if push button is pressed while the */
- /* buzzer is active, turn off the countdown for 10 */
- /* minutes, else keep repeating it. Also display */
- /* "Please Take Your Medicine" while the buzzer is */
- /* active */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* ring buzzer and motor every 1 minute for 5 */
- /* minutes. if push button is pressed while the */
- /* buzzer is active, turn off the countdown for 10 */
- /* minutes, else keep repeating it. Also display */
- /* "Please Take Your Medicine" while the buzzer is */
- /* active */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Adafruit_SSD1306.h> //https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
- #include <U8g2_for_Adafruit_GFX.h> //https://github.com/olikraus/U8g2_for_Adafruit_GFX
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void ringBuzzerAndMotor(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Reed_PushButton_PIN_D3 = 3;
- const uint8_t Reed_PushButton_PIN_D4 = 4;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Buzzer_PassiveBuzzer_Signal_PIN_D2 = 2;
- const uint8_t Vibrator_LED_PIN_D5 = 5;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t Screen_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
- const uint8_t Screen_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
- const uint8_t Screen_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 60;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
- bool Vibrator_LED_PIN_D5_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float Buzzer_PassiveBuzzer_Signal_PIN_D2_phyData = 0.0;
- float Vibrator_LED_PIN_D5_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, Screen_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
- bool pushButtonPressed = false;
- unsigned long lastPressTime = 0;
- unsigned long buzzerStartTime = 0;
- const unsigned long buzzerInterval = 60000; // 1 minute
- const unsigned long buzzerDuration = 300000; // 5 minutes
- const unsigned long pauseDuration = 600000; // 10 minutes
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Reed_PushButton_PIN_D3, INPUT_PULLUP);
- pinMode(Reed_PushButton_PIN_D4, INPUT_PULLUP);
- pinMode(Buzzer_PassiveBuzzer_Signal_PIN_D2, OUTPUT);
- pinMode(Vibrator_LED_PIN_D5, OUTPUT);
- display.begin(SSD1306_SWITCHCAPVCC, Screen_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
- display.display(); // Show initial display buffer contents on the screen
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- ringBuzzerAndMotor(); // Check and ring buzzer and motor
- }
- void updateOutputs()
- {
- digitalWrite(Buzzer_PassiveBuzzer_Signal_PIN_D2, Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData);
- digitalWrite(Vibrator_LED_PIN_D5, Vibrator_LED_PIN_D5_rawData);
- }
- void ringBuzzerAndMotor()
- {
- unsigned long currentTime = millis();
- if (!pushButtonPressed) {
- if (currentTime - buzzerStartTime >= buzzerInterval) {
- Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 1;
- Vibrator_LED_PIN_D5_rawData = 1;
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.println("Please Take Your Medicine");
- display.display();
- buzzerStartTime = currentTime;
- }
- if (currentTime - buzzerStartTime >= buzzerDuration) {
- Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
- Vibrator_LED_PIN_D5_rawData = 0;
- display.clearDisplay();
- display.display();
- buzzerStartTime = currentTime;
- }
- } else {
- if (currentTime - lastPressTime < pauseDuration) {
- Buzzer_PassiveBuzzer_Signal_PIN_D2_rawData = 0;
- Vibrator_LED_PIN_D5_rawData = 0;
- display.clearDisplay();
- display.display();
- } else {
- pushButtonPressed = false;
- }
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement