MUstar

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

Jun 15th, 2017
57
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2. int pin_LED[8] = {22,24,26,28,30,32,34,36};
  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.   lcd.begin(16,2);
  12.   lcd.print("ADC Data :");
  13.   lcd.setCursor(0, 1);
  14.   lcd.print("Volt :      [V]");
  15.   for(int i=0; i<8; i++)
  16.   {
  17.     pinMode(pin_LED[i],OUTPUT);
  18.     digitalWrite(pin_LED[i], LOW);
  19.   }
  20. }
  21.  
  22. void loop() {
  23.   uint16_t da = analogRead(pin_VR);
  24.   float voltage = (float)da * 5 /1023;
  25.   int led_mv = (da+110)/80;
  26.   int mv_num = 1;
  27.   lcd.setCursor(11, 0);
  28.   if(da<1000){lcd.print(" ");}
  29.   if(da<100){lcd.print(" ");}
  30.   if(da<10){lcd.print(" ");}
  31.   lcd.print(da);
  32.   lcd.setCursor(8, 1);
  33.   lcd.print(voltage);
  34.   for(int i=0; i<led_mv; i++){
  35.     mv_num = mv_num*2;
  36.     int temp = mv_num - 1;
  37.     LED_control(temp);
  38.   }
  39.   delay(500);
  40. }
  41. void LED_control(uint8_t da)
  42. {
  43.   for(int i=0; i<8; i++)
  44.   {
  45.     digitalWrite(pin_LED[i], (da >> i) & 0x1);
  46.   }
  47. }
RAW Paste Data