Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- //#include <math.h>
- int pin_LED[8] = {22,24,26,28,30,32,34,36};
- int pin_VR = A1;
- int pin_LCD_DATA[8] = {A8,A9,A10,A11,A12,A13,A14,A15};
- int pin_LCD_CTRL[3] = {A5,A6,A7};
- LiquidCrystal lcd(A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15);
- int cksum = 0;
- void setup() {
- pinMode(pin_VR, INPUT);
- lcd.begin(16,2);
- for(int i=0; i<8; i++)
- {
- pinMode(pin_LED[i],OUTPUT);
- digitalWrite(pin_LED[i], LOW);
- }
- }
- void loop() {
- uint16_t da = analogRead(pin_VR);
- float calc = (float)da/25;
- float cal2 = (float)da/50;
- int gogo = -1;
- int go_move = ceil(calc);
- int go_move_h = ceil(cal2) *2 ;
- //lcd.clear();lcd.print(go_move);delay(500); //Debug
- if(go_move<2){
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("O");
- LED_control(0);
- delay(500);
- }
- else{
- if(go_move<16){
- if(go_move > 14) LED_control(255);
- //else LED_control(0);
- lcd.clear();
- lcd.setCursor(go_move, 0);
- lcd.print("O");
- delay(500);
- }
- else{
- if(go_move == 16) LED_control(255);
- //else LED_control(0);
- for(int t=1;t<=go_move-15;t++)
- {
- gogo+=2;
- }
- lcd.clear();
- if(go_move == 29) cksum=1;
- if(cksum == 1){
- go_move++;
- cksum=0;
- }
- lcd.setCursor(go_move - gogo, 1);
- lcd.print("O");
- if(go_move > 29) LED_control(0);
- delay(500);
- }
- }
- }
- void LED_control(uint8_t da)
- {
- for(int i=0; i<8; i++)
- {
- digitalWrite(pin_LED[i], (da >> i) & 0x1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement