sábado, 30 de julio de 2022

OXIMETRO con MAX30100 LCD OLED 1.3 | arduino desde cero @Editronikx

 código


#include <SPI.h>
#include <Wire.h>
//#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#include "MAX30100_PulseOximeter.h"
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
#define REPORTING_PERIOD_MS     1000
PulseOximeter pox;
uint32_t tsLastReport = 0;
int pulso = 2;
void onBeatDetected()
{
    Serial.println("Beat!");
    digitalWrite(pulso, HIGH);
}
void setup()  
{          
  pinMode(pulso,OUTPUT);      
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3D (for the 128x64)
  display.clearDisplay();
  display.display();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("oximetro...!");
  display.display();
  delay(2000);
  Serial.begin(115200);
    Serial.print("Initializing pulse oximeter..");
 
    // Initialize the PulseOximeter instance
    // Failures are generally due to an improper I2C wiring, missing power supply
    // or wrong target chip
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
     pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
 
    // Register a callback for the beat detection
    pox.setOnBeatDetectedCallback(onBeatDetected);
 
}


void loop()
{
    // Make sure to call update as fast as possible
    pox.update();
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Serial.print("Heart rate:");
        Serial.print(pox.getHeartRate());
        Serial.print("bpm / SpO2:");
        Serial.print(pox.getSpO2());
        Serial.println("%");
 
        tsLastReport = millis();
        display.clearDisplay();
        display.display();
        display.setTextSize(1);
        display.setTextColor(WHITE);
        display.setCursor(0,0);
        display.println("OK!");
        //display.println(pox.getHeartRate());
        display.display();
        digitalWrite(pulso, LOW);
    }
  
}

domingo, 15 de mayo de 2022

sabes como crear menú en lcd con arduino? hoy te explico paso a paso | a...

#include <Key.h>
#include <Keypad.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'},
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char key;
int dato;
void setup()
{
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
  lcd.init();                      
  lcd.backlight();
  lcd.setCursor(2,0);
  lcd.print("Hola amigos");
  lcd.setCursor(2,1);
  lcd.print("BIENVENIDOS");
  lcd.setCursor(2,2);
  lcd.print("CANAL EDITRONIKX");
  delay(3000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("seleccione el menu");
  lcd.setCursor(3,2);
  lcd.print("con su teclado");
  delay(3000);
  lcd.clear();
}


void loop()
{
  lcd.setCursor(0,0);
  lcd.print("1.CONTROL LED");
  lcd.setCursor(0,1);
  lcd.print("2.JUEGO DE LUCES");
  lcd.setCursor(0,2);
  lcd.print("3.ACERCA DE...");
  key = keypad.getKey();
  
  if (key)
  {
    if(key == '1')
    { 
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("1.prender LED");
      lcd.setCursor(0,1);
      lcd.print("2.apagar LED");
      lcd.setCursor(0,2);
      lcd.print("3.Menu principal");
      dato = 1;
      while(dato)
      {
        key = keypad.getKey();
        if(key == '1')
        {
          digitalWrite(13,HIGH);
          lcd.setCursor(0,3);
          lcd.print("LED ONN");
        }
        if(key == '2')
        {
          digitalWrite(13,LOW);
          lcd.setCursor(0,3);
          lcd.print("LED OFF");
        }
        if(key == '3')
        {
          dato = 0;
          lcd.clear();
          lcd.setCursor(0,3);
          lcd.print("RETORNANDO MENU");
          delay(2000);
          lcd.clear();
          key = 0;
        }
      }

    }
//////////////////////////////////
  if(key == '2')
    {
      lcd.clear();
      dato = 1;
      while(dato)
      {
      lcd.setCursor(3,1);
      lcd.print("JUEGO DE LUCES");
      lcd.setCursor(3,2);
      lcd.print("3.Menu principal");
      key = keypad.getKey();
        if(key == '3')
        {
          dato = 0;
          lcd.clear();
          lcd.setCursor(0,3);
          lcd.print("RETORNANDO MENU");
          delay(2000);
          lcd.clear();
          key = 0;
        }
        for(int i=0;i<3; i++)
        {
          digitalWrite(13,HIGH);
          delay(100);
          digitalWrite(13,LOW);
          delay(100);
          
        }
      }
    }
    //////
    if(key == '3')
    {
       lcd.clear();
       lcd.setCursor(0,0);
       lcd.print("programa creado por");
       lcd.setCursor(0,1);
       lcd.print("editronikx 2022");
       lcd.setCursor(0,3);
       lcd.print("SUSCRIBETE...");
       delay(4000);
       lcd.clear();
    }
  
  }
}