Advertisement
MUstar

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

Jun 15th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. int pin_VIB = 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_VIB, 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 vid_v = (int)voltage;
  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.     if((voltage>=2)&&(voltage<=2.5))
  31.   {
  32.     digitalWrite(pin_VIB,HIGH);
  33.     delay(500);
  34.   }
  35.   else
  36.   {
  37.   digitalWrite(pin_VIB,LOW);
  38.   delay(500);
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement