Jump to content
ELFORUM - Forumul electronistilor

probleme buzzer

Guest silvestru docs

Recommended Posts

Guest silvestru docs

Va salut.
Am facut un proiect cu un detector de alcool cu MQ3 si merge foarte bine.Dar am intampinat o problema.Vreau sa-i adaug un buzzer ca sa sune numai la instructiunea if (value>=200 && value<280) ,cand apare pe LCD. display.println("You had a beer."); , si nu merge. Am gresit cu ceva in cod ? Orice raspuns e bine venit. Sunt incepator. 

Acesta este codul.


#include <SPI.h>#include <Wire.h>#include <Adafruit_GFX.h>#include <Adafruit_SSD1306.h>#define OLED_RESET 4int TIME_UNTIL_WARMUP = 900;unsigned long time;int analogPin = 0;int val = 0;int buzzer = 10;Adafruit_SSD1306 display(OLED_RESET);void setup() { display.begin(SSD1306_SWITCHCAPVCC, 0x3C);display.clearDisplay();pinMode(10,OUTPUT);}void loop() { delay(100);val = readAlcohol();printTitle();printWarming();time = millis()/1000;if(time<=TIME_UNTIL_WARMUP){time = map(time, 0, TIME_UNTIL_WARMUP, 0, 100);display.drawRect(10, 50, 110, 10, WHITE); //Empty Bardisplay.fillRect(10, 50, time,10,WHITE);}else{printTitle();printAlcohol(val);printAlcoholLevel(val); }display.display();}void printTitle(){display.clearDisplay();display.setTextSize(1);display.setTextColor(WHITE);display.setCursor(22,0);display.println("Breath Analyzer");}void printWarming(){display.setTextSize(2);display.setTextColor(WHITE);display.setCursor(0,20);display.println("Warming up");}void printAlcohol(int value){display.setTextSize(2);display.setTextColor(WHITE);display.setCursor(45,25);display.println(val);}void printAlcoholLevel(int value){display.setTextSize(1);display.setTextColor(WHITE);display.setCursor(10,55);if(value<200){display.println("You are sober.");}if (value>=200 && value<280){display.println("You had a beer.");digitalWrite(10,HIGH);}if (value>=280 && value<350){display.println("Two or more beers.");}if (value>=350 && value <450){display.println("I smell Oyzo!");}if(value>450){display.println("You are drunk!");digitalWrite(10,HIGH);}}int readAlcohol(){int val = 0;int val1;int val2;int val3; display.clearDisplay();val1 = analogRead(analogPin); delay(10);val2 = analogRead(analogPin); delay(10);val3 = analogRead(analogPin);val = (val1+val2+val3)/3;return val;
Link to comment
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic


Pe viitor foloseste butonul de inserare/formatare a codului (pe bara de meniu a editorului este semnul "<>".


In alta ordine de idei, ar fi sanatos sa scrii in loc de :

if (value>=200 && value <280)
if ((value>=200) && (value <280))

altfel confuzezi compilatorul.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines