Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <memorysaver.h>
- #include <UTFT.h>
- UTFT myGLCD(CTE32,38,39,40,41);
- extern uint8_t Grotesk32x64[];
- extern uint8_t SmallFont[];
- extern uint8_t BigFont[];
- extern uint8_t SevenSegNumFont[];
- extern unsigned short banana4[76800];
- extern unsigned short fr[400];
- volatile long encoder0Pos = 0;
- volatile boolean encoder0Switch = 0;
- unsigned int tmp = 0;
- int L1 = A0;
- #define encoder0PinA 2
- #define encoder0PinSwitch 3
- #define encoder0PinB 4
- #define ROTORE_ON 8
- #define inversione 9
- float pos_voluta;
- int V1 ;
- void setup() {
- Serial.begin(9600);
- myGLCD.InitLCD();
- myGLCD.clrScr();
- pinMode(encoder0PinA, INPUT_PULLUP);
- pinMode(encoder0PinB, INPUT_PULLUP);
- pinMode(encoder0PinSwitch, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(encoder0PinA), doEncoderA, RISING);
- attachInterrupt(digitalPinToInterrupt(encoder0PinSwitch), doSwitch, RISING);
- pinMode(A0, INPUT);
- pinMode(ROTORE_ON, OUTPUT);
- pinMode(inversione, OUTPUT);
- analogReadResolution(12);
- myGLCD.drawBitmap(0, 0,320,240, banana4);
- delay(5000);
- myGLCD.fillScr(0, 0, 0);
- myGLCD.setColor(255, 0, 0);
- myGLCD.setBackColor(0, 0, 0);
- myGLCD.setFont(Grotesk32x64);
- myGLCD.print( "IZ2ZMW", CENTER, 50);
- myGLCD.print("ROTOR", CENTER, 120);
- delay(5000);
- myGLCD.fillScr( 0, 0, 0);
- myGLCD.setColor(255,255,255);
- myGLCD.drawCircle(220,120, 90);
- myGLCD.drawRoundRect(0, 0, 130,80);
- myGLCD.setFont(SmallFont);
- myGLCD.print("POSIZIONE", 30, 10);
- myGLCD.drawRoundRect(0,160,130,239);
- myGLCD.print("POS.VOLUTA",30,170);
- myGLCD.setFont(BigFont);
- myGLCD.print("IZZMW",235, 10);
- myGLCD.print("2017", 250,220);
- myGLCD.drawLine(120,120,140,120);
- myGLCD.drawLine(300,120,319,120);
- myGLCD.drawLine(220,20,220, 40);
- myGLCD.drawLine(220,200,220,220);
- }
- void loop() {
- myGLCD.setFont(SevenSegNumFont);
- myGLCD.setColor(0,0,0);
- myGLCD.fillRect(10,25,110,75);
- myGLCD.setColor( 0,255, 0);
- myGLCD.printNumI(encoder0Pos, 15,25);
- myGLCD.setColor(0,0,0);
- myGLCD.fillRect(10,185,110,238);
- myGLCD.setColor( 0,255, 0);
- myGLCD.printNumI(pos_voluta, 15,185);
- myGLCD.setFont(BigFont);
- myGLCD.setColor(255, 0, 0);
- myGLCD.setColor(0, 0, 0);
- myGLCD.fillCircle(220,120,85);
- myGLCD.setColor( 0,255, 0);
- myGLCD.drawBitmap(218,42, 5, 80,fr,encoder0Pos, 3, 80);
- if (tmp != encoder0Pos) {
- tmp = encoder0Pos;
- }
- if (encoder0Switch) {
- encoder0Switch = 0;
- }
- // qui termina il void loop() ovvero quello che l'arduino esegue in continuazione
- }
- // Queste sono le funzioni eseguite sugli interrupt
- ////////////////////////////////////////////
- void doEncoderA(){
- if(digitalRead(encoder0PinB)) encoder0Pos--;
- else encoder0Pos++;
- }
- void doSwitch(){
- encoder0Switch = 1;
- encoder0Pos = 0;
- }
- ////////////////////////////////////////////
- // tutto questo codice cosi com'è al massimo viene eseguito una volta sola
- // (o forse proprio per nulla, andrebbe verificato).
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- V1 = analogRead(L1);
- //pos_voluta = V1/5.68;
- pos_voluta = 60;
- if(pos_voluta > 360) pos_voluta = 360;
- if(pos_voluta == encoder0Pos) {
- digitalWrite(ROTORE_ON, LOW);
- digitalWrite(inversione, LOW);
- myGLCD.setColor( 0, 0, 0);
- myGLCD.fillRect( 0,90,120,160);
- myGLCD.setColor( 0,255, 0);
- myGLCD.print("READY",20,110);
- }
- else if(pos_voluta < encoder0Pos) {
- digitalWrite(inversione, HIGH);
- digitalWrite(ROTORE_ON, HIGH);
- myGLCD.setColor( 0, 0, 0);
- myGLCD.fillRect( 0,90,120,160);
- myGLCD.setColor(255, 0, 0);
- myGLCD.print("ROTATE", 5,100);
- myGLCD.print("CCW", 30,130); }
- else {
- myGLCD.setColor( 0, 0, 0);
- myGLCD.fillRect( 0,90,120,160);
- myGLCD.setColor(255, 0, 0);
- digitalWrite(inversione, LOW);
- digitalWrite(ROTORE_ON, HIGH);
- myGLCD.print("ROTATE", 5,100);
- myGLCD.print("CW", 35,130);
- }
- // Cosa chiude questa parentesi?
- //////////////////////////////////
- }
- /////////////////////////////////////
- if(encoder0Pos > 360) {
- myGLCD.setColor(255, 0, 0);
- myGLCD.print("ERROR",140,220);
- digitalWrite(inversione, HIGH);
- digitalWrite(ROTORE_ON, HIGH);
- myGLCD.setColor(0, 0, 0);
- delay(10000);
- myGLCD.fillRect(140,210,220,239);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement