MUstar

IoT 아두이노 0616 - V/R + PIEZO

Jun 15th, 2017
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2. int pin_PIEZO = 22;
  3. int pin_VR = A1;
  4. int pin_LCD_DATA[8] = {A8,A9,A10,A11,A12,A13,A14,A15};
  5. int pin_LCD_CTRL[3] = {A5,A6,A7};
  6. LiquidCrystal lcd(A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15);
  7.  
  8.  
  9. void setup() {
  10.   pinMode(pin_VR, INPUT);
  11.   pinMode(pin_PIEZO, OUTPUT);
  12.   lcd.begin(16,2);
  13.   lcd.print("ADC Data :");
  14.   lcd.setCursor(0, 1);
  15.   lcd.print("Volt :      [V]");
  16.  
  17. }
  18.  
  19. void loop() {
  20.   uint16_t da = analogRead(pin_VR);
  21.   float voltage = (float)da * 5 /1023;
  22.   //int beep = ((float)((da)/70)*90);
  23.   lcd.setCursor(11, 0);
  24.   if(da<1000){lcd.print(" ");}
  25.   if(da<100){lcd.print(" ");}
  26.   if(da<10){lcd.print(" ");}
  27.   lcd.print(da);
  28.   lcd.setCursor(8, 1);
  29.   lcd.print(voltage);
  30.   tone(pin_PIEZO, da);
  31.   delay(500);
  32. }
RAW Paste Data