MUstar

IoT 아두이노 0616 - V/R + ("O")MOVE + LED ON/OFF

Jun 16th, 2017
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2. //#include <math.h>
  3. int pin_LED[8] = {22,24,26,28,30,32,34,36};
  4. int pin_VR = A1;
  5. int pin_LCD_DATA[8] = {A8,A9,A10,A11,A12,A13,A14,A15};
  6. int pin_LCD_CTRL[3] = {A5,A6,A7};
  7. LiquidCrystal lcd(A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15);
  8. int cksum = 0;
  9.  
  10. void setup() {
  11.   pinMode(pin_VR, INPUT);
  12.   lcd.begin(16,2);
  13.   for(int i=0; i<8; i++)
  14.   {
  15.     pinMode(pin_LED[i],OUTPUT);
  16.     digitalWrite(pin_LED[i], LOW);
  17.   }
  18. }
  19.  
  20. void loop() {
  21.   uint16_t da = analogRead(pin_VR);
  22.   float calc = (float)da/25;
  23.   float cal2 = (float)da/50;
  24.   int gogo = -1;
  25.   int go_move = ceil(calc);
  26.   int go_move_h = ceil(cal2) *2 ;
  27.   //lcd.clear();lcd.print(go_move);delay(500); //Debug
  28.  
  29.   if(go_move<2){
  30.     lcd.clear();
  31.     lcd.setCursor(0, 0);
  32.     lcd.print("O");
  33.     LED_control(0);
  34.     delay(500);
  35.   }
  36.   else{
  37.     if(go_move<16){
  38.       if(go_move > 14) LED_control(255);
  39.       //else LED_control(0);
  40.       lcd.clear();
  41.       lcd.setCursor(go_move, 0);
  42.       lcd.print("O");
  43.       delay(500);
  44.     }
  45.     else{
  46.       if(go_move == 16) LED_control(255);
  47.       //else LED_control(0);
  48.       for(int t=1;t<=go_move-15;t++)
  49.       {
  50.         gogo+=2;
  51.       }
  52.       lcd.clear();
  53.       if(go_move == 29) cksum=1;
  54.       if(cksum == 1){
  55.         go_move++;
  56.         cksum=0;  
  57.       }
  58.       lcd.setCursor(go_move - gogo, 1);
  59.       lcd.print("O");
  60.       if(go_move > 29) LED_control(0);
  61.       delay(500);
  62.     }
  63.   }
  64. }
  65.  
  66. void LED_control(uint8_t da)
  67. {
  68.   for(int i=0; i<8; i++)
  69.   {
  70.     digitalWrite(pin_LED[i], (da >> i) & 0x1);
  71.   }
  72. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×