Advertisement
Guest User

Untitled

a guest
Jan 13th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.   LiquidCrystal lcd(4,5,6,7,8,9);
  3. const int numReadings = 3;
  4. int readings[numReadings];      // the readings from the analog input
  5. int readIndex = 0;              // the index of the current reading
  6. int total = 0;                  // the running total
  7. int average = 0;                // the average
  8. byte egyotod[8] = {
  9.   0b10000,
  10.   0b10000,
  11.   0b10000,
  12.   0b10000,
  13.   0b10000,
  14.   0b10000,
  15.   0b10000,
  16.   0b10000
  17. };
  18. byte ketotod[8] = {
  19.   0b11000,
  20.   0b11000,
  21.   0b11000,
  22.   0b11000,
  23.   0b11000,
  24.   0b11000,
  25.   0b11000,
  26.   0b11000
  27. };
  28. byte haromotod[8] = {
  29.   0b11100,
  30.   0b11100,
  31.   0b11100,
  32.   0b11100,
  33.   0b11100,
  34.   0b11100,
  35.   0b11100,
  36.   0b11100
  37. };
  38. byte negyotod[8] = {
  39.   0b11110,
  40.   0b11110,
  41.   0b11110,
  42.   0b11110,
  43.   0b11110,
  44.   0b11110,
  45.   0b11110,
  46.   0b11110
  47. };
  48. byte egesz[8] = {
  49.   0b11111,
  50.   0b11111,
  51.   0b11111,
  52.   0b11111,
  53.   0b11111,
  54.   0b11111,
  55.   0b11111,
  56.   0b11111
  57. };
  58.  
  59. void setup() {
  60.     pinMode(A0, INPUT);
  61.     pinMode(10,OUTPUT);
  62.     lcd.begin(20, 4);
  63.     lcd.createChar(0, egyotod);
  64.     lcd.createChar(1, ketotod);
  65.     lcd.createChar(2, haromotod);
  66.     lcd.createChar(3, negyotod);
  67.     lcd.createChar(4, egesz);  
  68.       for (int thisReading = 0; thisReading < numReadings; thisReading++) {
  69.     readings[thisReading] = 0;
  70.   }
  71. }
  72. void loop() {
  73.  
  74. total = total - readings[readIndex];
  75.   // read from the sensor:
  76.   readings[readIndex] = analogRead(A5);
  77.   // add the reading to the total:
  78.   total = total + readings[readIndex];
  79.   // advance to the next position in the array:
  80.   readIndex = readIndex + 1;
  81.   // if we're at the end of the array...
  82.   if (readIndex >= numReadings) {
  83.     // ...wrap around to the beginning:
  84.     readIndex = 0;
  85.   }
  86.  
  87.   // calculate the average:
  88.   average = total / numReadings;
  89.   // send it to the computer as ASCII digits
  90.   int eredetival = average;
  91.   delay(1);        // delay in between reads for stability
  92.   int val = map(eredetival, 0, 1023, 0, 40);
  93. if(val%5==0)
  94. {
  95.   lcd.setCursor(1,1);
  96.   if(val!=0)
  97.   for(int i=0;i-1<val/5;i++)
  98.   {
  99.    lcd.write((uint8_t)4);
  100.    lcd.setCursor(1+i,1);
  101.   }
  102. }
  103. else
  104. {
  105.   int x = val-val%5; //megkapom a maradékot, ezt oszthatom le tovább
  106.   lcd.setCursor(1,1);
  107.   int kulsoi=0;
  108.   for(int i=0;i-1<x/5;i++)
  109.   {
  110.    lcd.write((uint8_t)4);
  111.    lcd.setCursor(1+i,1);
  112.    kulsoi=i;
  113.   }
  114.   lcd.setCursor(1+kulsoi,1);
  115.   lcd.write((val%5)-1);
  116.   }
  117. delay(35);
  118. lcd.clear();
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement