Advertisement
TolentinoCotesta

Errori

May 9th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.26 KB | None | 0 0
  1. #include <memorysaver.h>
  2. #include <UTFT.h>
  3.  
  4. UTFT myGLCD(CTE32,38,39,40,41);
  5. extern uint8_t Grotesk32x64[];
  6. extern uint8_t SmallFont[];
  7. extern uint8_t BigFont[];
  8. extern uint8_t SevenSegNumFont[];
  9. extern unsigned short   banana4[76800];
  10. extern unsigned short fr[400];
  11. volatile long  encoder0Pos = 0;
  12. volatile boolean encoder0Switch = 0;
  13. unsigned int tmp = 0;                  
  14.  
  15. int L1 = A0;      
  16.  
  17. #define encoder0PinA 2
  18. #define encoder0PinSwitch 3
  19. #define encoder0PinB 4
  20. #define ROTORE_ON     8          
  21. #define inversione    9
  22. float pos_voluta;
  23. int V1 ;
  24. void setup() {
  25.  Serial.begin(9600);
  26.  myGLCD.InitLCD();
  27.  myGLCD.clrScr();
  28.   pinMode(encoder0PinA, INPUT_PULLUP);
  29.   pinMode(encoder0PinB, INPUT_PULLUP);
  30.   pinMode(encoder0PinSwitch, INPUT_PULLUP);
  31.   attachInterrupt(digitalPinToInterrupt(encoder0PinA), doEncoderA, RISING);
  32.   attachInterrupt(digitalPinToInterrupt(encoder0PinSwitch), doSwitch, RISING);  
  33.  pinMode(A0, INPUT);
  34.  pinMode(ROTORE_ON, OUTPUT);
  35. pinMode(inversione, OUTPUT);
  36. analogReadResolution(12);
  37. myGLCD.drawBitmap(0, 0,320,240, banana4);
  38. delay(5000);
  39. myGLCD.fillScr(0, 0, 0);
  40.   myGLCD.setColor(255, 0, 0);
  41.  myGLCD.setBackColor(0, 0, 0);
  42.  myGLCD.setFont(Grotesk32x64);
  43.  myGLCD.print( "IZ2ZMW", CENTER, 50);
  44.  myGLCD.print("ROTOR", CENTER, 120);
  45.  delay(5000);
  46. myGLCD.fillScr( 0, 0, 0);
  47. myGLCD.setColor(255,255,255);
  48. myGLCD.drawCircle(220,120, 90);
  49. myGLCD.drawRoundRect(0, 0, 130,80);
  50. myGLCD.setFont(SmallFont);
  51. myGLCD.print("POSIZIONE", 30, 10);
  52. myGLCD.drawRoundRect(0,160,130,239);
  53. myGLCD.print("POS.VOLUTA",30,170);
  54. myGLCD.setFont(BigFont);
  55. myGLCD.print("IZZMW",235, 10);
  56. myGLCD.print("2017", 250,220);
  57. myGLCD.drawLine(120,120,140,120);
  58. myGLCD.drawLine(300,120,319,120);
  59. myGLCD.drawLine(220,20,220, 40);
  60. myGLCD.drawLine(220,200,220,220);
  61.  
  62.  
  63. }
  64.  
  65. void loop() {
  66.   myGLCD.setFont(SevenSegNumFont);
  67.   myGLCD.setColor(0,0,0);
  68.   myGLCD.fillRect(10,25,110,75);
  69.   myGLCD.setColor( 0,255, 0);
  70.   myGLCD.printNumI(encoder0Pos, 15,25);
  71.   myGLCD.setColor(0,0,0);
  72.   myGLCD.fillRect(10,185,110,238);
  73.   myGLCD.setColor( 0,255, 0);
  74.   myGLCD.printNumI(pos_voluta, 15,185);
  75.   myGLCD.setFont(BigFont);
  76.   myGLCD.setColor(255, 0, 0);
  77.  
  78.  
  79. myGLCD.setColor(0, 0, 0);
  80. myGLCD.fillCircle(220,120,85);
  81.  myGLCD.setColor( 0,255, 0);
  82.  myGLCD.drawBitmap(218,42, 5, 80,fr,encoder0Pos, 3, 80);
  83.  
  84.  if (tmp != encoder0Pos) {
  85.       tmp = encoder0Pos;
  86.   }
  87.   if (encoder0Switch) {
  88.         encoder0Switch = 0;
  89.    
  90.   }
  91.  
  92.  
  93. // qui termina il void loop() ovvero quello che l'arduino esegue in continuazione
  94.   }
  95.  
  96. // Queste sono le funzioni eseguite sugli interrupt
  97. ////////////////////////////////////////////
  98. void doEncoderA(){
  99.   if(digitalRead(encoder0PinB)) encoder0Pos--;
  100.     else encoder0Pos++;
  101. }
  102. void doSwitch(){
  103.   encoder0Switch = 1;
  104.   encoder0Pos = 0;
  105. }
  106. ////////////////////////////////////////////
  107.  
  108.  
  109.  
  110. // tutto questo codice cosi com'è al massimo viene eseguito una volta sola
  111. // (o forse proprio per nulla, andrebbe verificato).
  112. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  113.  V1 = analogRead(L1);
  114. //pos_voluta = V1/5.68;
  115. pos_voluta = 60;
  116. if(pos_voluta > 360) pos_voluta = 360;
  117.  
  118.  if(pos_voluta == encoder0Pos)  {
  119.  digitalWrite(ROTORE_ON, LOW);
  120.  digitalWrite(inversione, LOW);
  121.  myGLCD.setColor( 0, 0, 0);
  122.  myGLCD.fillRect( 0,90,120,160);
  123.  myGLCD.setColor( 0,255, 0);
  124.  myGLCD.print("READY",20,110);
  125.  }
  126.  
  127.  else if(pos_voluta < encoder0Pos) {
  128.    digitalWrite(inversione, HIGH);
  129.  digitalWrite(ROTORE_ON, HIGH);
  130.   myGLCD.setColor( 0, 0, 0);
  131.  myGLCD.fillRect( 0,90,120,160);  
  132. myGLCD.setColor(255, 0, 0);
  133.  myGLCD.print("ROTATE", 5,100);
  134.  myGLCD.print("CCW", 30,130); }
  135.  
  136. else  {
  137.    myGLCD.setColor( 0, 0, 0);
  138.  myGLCD.fillRect( 0,90,120,160);
  139.  myGLCD.setColor(255, 0, 0);
  140.  digitalWrite(inversione, LOW);
  141.  digitalWrite(ROTORE_ON, HIGH);
  142.  myGLCD.print("ROTATE", 5,100);
  143.  myGLCD.print("CW", 35,130);  
  144.  }
  145.  
  146. // Cosa chiude questa parentesi?
  147. //////////////////////////////////
  148.  }
  149. /////////////////////////////////////
  150.  
  151.  if(encoder0Pos > 360) {
  152.  myGLCD.setColor(255, 0, 0);
  153.  myGLCD.print("ERROR",140,220);
  154.  digitalWrite(inversione, HIGH);
  155.  digitalWrite(ROTORE_ON, HIGH);
  156. myGLCD.setColor(0, 0, 0);
  157. delay(10000);
  158. myGLCD.fillRect(140,210,220,239);
  159.  
  160.  
  161.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement