Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(4,5,6,7,8,9);
- const int numReadings = 3;
- int readings[numReadings]; // the readings from the analog input
- int readIndex = 0; // the index of the current reading
- int total = 0; // the running total
- int average = 0; // the average
- byte egyotod[8] = {
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b10000
- };
- byte ketotod[8] = {
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000,
- 0b11000
- };
- byte haromotod[8] = {
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100,
- 0b11100
- };
- byte negyotod[8] = {
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110,
- 0b11110
- };
- byte egesz[8] = {
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111,
- 0b11111
- };
- void setup() {
- pinMode(A0, INPUT);
- pinMode(10,OUTPUT);
- lcd.begin(20, 4);
- lcd.createChar(0, egyotod);
- lcd.createChar(1, ketotod);
- lcd.createChar(2, haromotod);
- lcd.createChar(3, negyotod);
- lcd.createChar(4, egesz);
- for (int thisReading = 0; thisReading < numReadings; thisReading++) {
- readings[thisReading] = 0;
- }
- }
- void loop() {
- total = total - readings[readIndex];
- // read from the sensor:
- readings[readIndex] = analogRead(A5);
- // add the reading to the total:
- total = total + readings[readIndex];
- // advance to the next position in the array:
- readIndex = readIndex + 1;
- // if we're at the end of the array...
- if (readIndex >= numReadings) {
- // ...wrap around to the beginning:
- readIndex = 0;
- }
- // calculate the average:
- average = total / numReadings;
- // send it to the computer as ASCII digits
- int eredetival = average;
- delay(1); // delay in between reads for stability
- int val = map(eredetival, 0, 1023, 0, 40);
- if(val%5==0)
- {
- lcd.setCursor(1,1);
- if(val!=0)
- for(int i=0;i-1<val/5;i++)
- {
- lcd.write((uint8_t)4);
- lcd.setCursor(1+i,1);
- }
- }
- else
- {
- int x = val-val%5; //megkapom a maradékot, ezt oszthatom le tovább
- lcd.setCursor(1,1);
- int kulsoi=0;
- for(int i=0;i-1<x/5;i++)
- {
- lcd.write((uint8_t)4);
- lcd.setCursor(1+i,1);
- kulsoi=i;
- }
- lcd.setCursor(1+kulsoi,1);
- lcd.write((val%5)-1);
- }
- delay(35);
- lcd.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement