Arduino code for the Camera Slider.





Recently i have gotten some request for sharing the Arduino code for my homemade camera slider.

To start with i just want to say, I’m no master in this, so there can be bugs, and the code is still early and not complete.

Recently i haven’t had much time for these kind of projects, so it has been still for a while.

You can see the serie below here.

If you like the videos please consider liking and sharing the videos, that will keep me working on these projects.

Make a Contribution - So i can make more projects Contribute 1$ Contribute 5$ Contribute 10$ Other Amount:

Camera_Slider.ino

#include "Timer.h" #include <Adafruit_GFX.h> // Core graphics library #include "SWTFT.h" // Hardware-specific library #include <TouchScreen.h> int pin02 = 11; Timer t; int tid=1000; int stepspeed=1000; int steplenght=10; boolean stepdirection=LOW; char buf[12]; int dirpin = 9; int steppin = 10; int interrupt_pin = 12; int eventid; bool runok = false; // Assign human-readable names to some common 16-bit color values: #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define YP A1 // must be an analog pin, use "An" notation! #define XM A2 // must be an analog pin, use "An" notation! #define YM 7 // can be a digital pin #define XP 6 // can be a digital pin #define TS_MINX 150 #define TS_MINY 60 #define TS_MAXX 1230 #define TS_MAXY 690 #define MINPRESSURE 10 #define MAXPRESSURE 1000 // For better pressure precision, we need to know the resistance // between X+ and X- Use any multimeter to read it // For the one we're using, its 300 ohms across the X plate TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); SWTFT tft; void takeReading() { runstepper(); delay(250); digitalWrite(pin02, !digitalRead(pin02)); delay(250); digitalWrite(pin02, !digitalRead(pin02)); } void runstepper() { int i; digitalWrite(dirpin, stepdirection); // Set the direction. for (i = 0; i<steplenght; i++) // Iterate for 4000 microsteps. { if(runok) { digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the delayMicroseconds(steplenght); digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step. delayMicroseconds(stepspeed); // This delay time is close to top speed for this } } } void stopall() { t.stop(eventid); tft.setCursor(80, 100); tft.setTextColor(BLUE); tft.setTextSize(2); tft.println("Stop"); delay(250); tft.setCursor(80, 100); tft.setTextColor(WHITE); tft.setTextSize(2); tft.println("Stop"); } void InitialiseIO(){ pinMode(A5, INPUT); // Pin A2 is input to which a switch is connected digitalWrite(A5, HIGH); // Configure internal pull-up resistor } void InitialiseInterrupt(){ cli(); // switch interrupts off while messing with their settings PCICR =0x02; // Enable PCINT1 interrupt PCMSK1 = 0b00100000; sei(); // turn interrupts back on } ISR(PCINT1_vect) { // Interrupt service routine. Every single PCINT8..14 (=ADC0..5) change // will generate an interrupt: but this will always be the same interrupt routine runok = false; if (digitalRead(A5)==0) Serial.println("A5"); stopall(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 #include "Timer.h" #include <Adafruit_GFX.h> // Core graphics library #include "SWTFT.h" // Hardware-specific library #include <TouchScreen.h> int pin02 = 11 ; Timer t ; int tid = 1000 ; int stepspeed = 1000 ; int steplenght = 10 ; boolean stepdirection = LOW ; char buf [ 12 ] ; int dirpin = 9 ; int steppin = 10 ; int interrupt_pin = 12 ; int eventid ; bool runok = false ; // Assign human-readable names to some common 16-bit color values: #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define YP A1 // must be an analog pin, use "An" notation! #define XM A2 // must be an analog pin, use "An" notation! #define YM 7 // can be a digital pin #define XP 6 // can be a digital pin #define TS_MINX 150 #define TS_MINY 60 #define TS_MAXX 1230 #define TS_MAXY 690 #define MINPRESSURE 10 #define MAXPRESSURE 1000 // For better pressure precision, we need to know the resistance // between X+ and X- Use any multimeter to read it // For the one we're using, its 300 ohms across the X plate TouchScreen ts = TouchScreen ( XP , YP , XM , YM , 300 ) ; SWTFT tft ; void takeReading ( ) { runstepper ( ) ; delay ( 250 ) ; digitalWrite ( pin02 , ! digitalRead ( pin02 ) ) ; delay ( 250 ) ; digitalWrite ( pin02 , ! digitalRead ( pin02 ) ) ; } void runstepper ( ) { int i ; digitalWrite ( dirpin , stepdirection ) ; // Set the direction. for ( i = 0 ; i < steplenght ; i ++ ) // Iterate for 4000 microsteps. { if ( runok ) { digitalWrite ( steppin , LOW ) ; // This LOW to HIGH change is what creates the delayMicroseconds ( steplenght ) ; digitalWrite ( steppin , HIGH ) ; // "Rising Edge" so the easydriver knows to when to step. delayMicroseconds ( stepspeed ) ; // This delay time is close to top speed for this } } } void stopall ( ) { t . stop ( eventid ) ; tft . setCursor ( 80 , 100 ) ; tft . setTextColor ( BLUE ) ; tft . setTextSize ( 2 ) ; tft . println ( "Stop" ) ; delay ( 250 ) ; tft . setCursor ( 80 , 100 ) ; tft . setTextColor ( WHITE ) ; tft . setTextSize ( 2 ) ; tft . println ( "Stop" ) ; } void InitialiseIO ( ) { pinMode ( A5 , INPUT ) ; // Pin A2 is input to which a switch is connected digitalWrite ( A5 , HIGH ) ; // Configure internal pull-up resistor } void InitialiseInterrupt ( ) { cli ( ) ; // switch interrupts off while messing with their settings PCICR = 0x02 ; // Enable PCINT1 interrupt PCMSK1 = 0b00100000 ; sei ( ) ; // turn interrupts back on } ISR ( PCINT1_vect ) { // Interrupt service routine. Every single PCINT8..14 (=ADC0..5) change // will generate an interrupt: but this will always be the same interrupt routine runok = false ; if ( digitalRead ( A5 ) == 0 ) Serial . println ( "A5" ) ; stopall ( ) ; }

Grapichs.ino

#define BOXSIZE_S 40 #define BOXSIZE 60 #define BOXSIZE_L 80 void Text() { tft.fillScreen(WHITE); // Makes white line to make a Button tft.fillRect(0, 0, BOXSIZE, BOXSIZE+BOXSIZE, GREEN); //Start tft.drawRect(0, 0, BOXSIZE, BOXSIZE+BOXSIZE, WHITE); //Start tft.setCursor(20, 10); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("S"); //Second value tft.setCursor(20, 30); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("T"); //Third value tft.setCursor(20, 50); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("A"); //Fifth value tft.setCursor(20, 70); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("R"); tft.setCursor(20, 90); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("T"); tft.fillRect(0, BOXSIZE*2, BOXSIZE, BOXSIZE+BOXSIZE, RED); //stop tft.drawRect(0, BOXSIZE*2, BOXSIZE, BOXSIZE+BOXSIZE, WHITE); //stop tft.setCursor(20, 140); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("S"); //Second value tft.setCursor(20, 160); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("T"); //Third value tft.setCursor(20, 180); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("O"); //Fifth value tft.setCursor(20, 200); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("P"); // Right Arrow Boxes ***************************************************************************** tft.drawRect(260, 0, BOXSIZE, BOXSIZE, BLACK); // +1sec tft.drawRect(260, BOXSIZE, BOXSIZE, BOXSIZE, BLACK); // +1speed tft.drawRect(260, BOXSIZE*2, BOXSIZE, BOXSIZE, BLACK); // +1Lenght tft.drawRect(260, BOXSIZE*3, BOXSIZE, BOXSIZE, BLACK); // Right Direction //First arrow tft.setCursor(280, 22); tft.setTextColor(RED); tft.setTextSize(3); tft.println("+"); //Second arrow tft.setCursor(280, 80); tft.setTextColor(RED); tft.setTextSize(3); tft.println("+"); //Third Arrow tft.setCursor(280, 142); tft.setTextColor(RED); tft.setTextSize(3); tft.println("+"); //Fifth arrow tft.setCursor(280, 200); tft.setTextColor(BLACK); tft.setTextSize(3); tft.println(">"); //****************************************************************************************************** // Value Boxes ***************************************************************************************** // tft.drawRect(220, 0, BOXSIZE_S, BOXSIZE, BLACK); // +1sec // tft.drawRect(220, BOXSIZE, BOXSIZE_S, BOXSIZE, BLACK); // +1speed // tft.drawRect(220, BOXSIZE*2, BOXSIZE_S, BOXSIZE, BLACK); // +1Lenght // tft.drawRect(220, BOXSIZE*3, BOXSIZE_S, BOXSIZE, BLACK); // Right Direction //First value tft.setCursor(235, 22); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println(itoa(tid/1000, buf, 10)); // tft.println("1"); //Second value tft.setCursor(235, 80); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println(itoa(stepspeed/100, buf, 10)); // tft.println("2"); //Third value tft.setCursor(235, 142); tft.setTextColor(BLACK); tft.setTextSize(2); // tft.println("3"); tft.println(itoa(steplenght/100, buf, 10)); //Fifth value tft.setCursor(235, 200); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("L"); //****************************************************************************************************** // Left Arrow Boxes ***************************************************************************** tft.drawRect(160, 0, BOXSIZE, BOXSIZE, BLACK); // +1sec tft.drawRect(160, BOXSIZE, BOXSIZE, BOXSIZE, BLACK); // +1speed tft.drawRect(160, BOXSIZE*2, BOXSIZE, BOXSIZE, BLACK); // +1Lenght tft.drawRect(160, BOXSIZE*3, BOXSIZE, BOXSIZE, BLACK); // Right Direction //First arrow tft.setCursor(180, 22); tft.setTextColor(BLUE); tft.setTextSize(3); tft.println("-"); //Second arrow tft.setCursor(180, 80); tft.setTextColor(BLUE); tft.setTextSize(3); tft.println("-"); //Third Arrow tft.setCursor(180, 142); tft.setTextColor(BLUE); tft.setTextSize(3); tft.println("-"); //Fifth arrow tft.setCursor(180, 200); tft.setTextColor(BLACK); tft.setTextSize(3); tft.println("<"); //****************************************************************************************************** // TEXT ************************************************************************************************ tft.setCursor(70, 22); tft.setTextColor(BLACK); tft.setTextSize(1); tft.println("Time / Seconds"); tft.setCursor(70, 80); tft.setTextColor(BLACK); tft.setTextSize(1); tft.println("Speed"); tft.setCursor(70, 142); tft.setTextColor(BLACK); tft.setTextSize(1); tft.println("Lenght / Travel"); tft.setCursor(70, 200); tft.setTextColor(BLACK); tft.setTextSize(1); tft.println("left/Right"); tft.setCursor(70, 230); tft.setTextColor(BLACK); tft.setTextSize(1); tft.println("V. 1.0"); // tft.setCursor(BOXSIZE_L+30, 23); // tft.setTextColor(WHITE); tft.setTextSize(3); // tft.println(itoa(tid/1000, buf, 10)); // Plus one second button text ************** //******************************************* // tft.setCursor(0, 100); // tft.setTextColor(GREEN); tft.setTextSize(4); // tft.println(" Pixeljunk.dk"); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 #define BOXSIZE_S 40 #define BOXSIZE 60 #define BOXSIZE_L 80 void Text ( ) { tft . fillScreen ( WHITE ) ; // Makes white line to make a Button tft . fillRect ( 0 , 0 , BOXSIZE , BOXSIZE + BOXSIZE , GREEN ) ; //Start tft . drawRect ( 0 , 0 , BOXSIZE , BOXSIZE + BOXSIZE , WHITE ) ; //Start tft . setCursor ( 20 , 10 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "S" ) ; //Second value tft . setCursor ( 20 , 30 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "T" ) ; //Third value tft . setCursor ( 20 , 50 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "A" ) ; //Fifth value tft . setCursor ( 20 , 70 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "R" ) ; tft . setCursor ( 20 , 90 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "T" ) ; tft . fillRect ( 0 , BOXSIZE* 2 , BOXSIZE , BOXSIZE + BOXSIZE , RED ) ; //stop tft . drawRect ( 0 , BOXSIZE* 2 , BOXSIZE , BOXSIZE + BOXSIZE , WHITE ) ; //stop tft . setCursor ( 20 , 140 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "S" ) ; //Second value tft . setCursor ( 20 , 160 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "T" ) ; //Third value tft . setCursor ( 20 , 180 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "O" ) ; //Fifth value tft . setCursor ( 20 , 200 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "P" ) ; // Right Arrow Boxes ***************************************************************************** tft . drawRect ( 260 , 0 , BOXSIZE , BOXSIZE , BLACK ) ; // +1sec tft . drawRect ( 260 , BOXSIZE , BOXSIZE , BOXSIZE , BLACK ) ; // +1speed tft . drawRect ( 260 , BOXSIZE* 2 , BOXSIZE , BOXSIZE , BLACK ) ; // +1Lenght tft . drawRect ( 260 , BOXSIZE* 3 , BOXSIZE , BOXSIZE , BLACK ) ; // Right Direction //First arrow tft . setCursor ( 280 , 22 ) ; tft . setTextColor ( RED ) ; tft . setTextSize ( 3 ) ; tft . println ( "+" ) ; //Second arrow tft . setCursor ( 280 , 80 ) ; tft . setTextColor ( RED ) ; tft . setTextSize ( 3 ) ; tft . println ( "+" ) ; //Third Arrow tft . setCursor ( 280 , 142 ) ; tft . setTextColor ( RED ) ; tft . setTextSize ( 3 ) ; tft . println ( "+" ) ; //Fifth arrow tft . setCursor ( 280 , 200 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 3 ) ; tft . println ( ">" ) ; //****************************************************************************************************** // Value Boxes ***************************************************************************************** // tft.drawRect(220, 0, BOXSIZE_S, BOXSIZE, BLACK); // +1sec // tft.drawRect(220, BOXSIZE, BOXSIZE_S, BOXSIZE, BLACK); // +1speed // tft.drawRect(220, BOXSIZE*2, BOXSIZE_S, BOXSIZE, BLACK); // +1Lenght // tft.drawRect(220, BOXSIZE*3, BOXSIZE_S, BOXSIZE, BLACK); // Right Direction //First value tft . setCursor ( 235 , 22 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( itoa ( tid / 1000 , buf , 10 ) ) ; // tft.println("1"); //Second value tft . setCursor ( 235 , 80 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( itoa ( stepspeed / 100 , buf , 10 ) ) ; // tft.println("2"); //Third value tft . setCursor ( 235 , 142 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; // tft.println("3"); tft . println ( itoa ( steplenght / 100 , buf , 10 ) ) ; //Fifth value tft . setCursor ( 235 , 200 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "L" ) ; //****************************************************************************************************** // Left Arrow Boxes ***************************************************************************** tft . drawRect ( 160 , 0 , BOXSIZE , BOXSIZE , BLACK ) ; // +1sec tft . drawRect ( 160 , BOXSIZE , BOXSIZE , BOXSIZE , BLACK ) ; // +1speed tft . drawRect ( 160 , BOXSIZE* 2 , BOXSIZE , BOXSIZE , BLACK ) ; // +1Lenght tft . drawRect ( 160 , BOXSIZE* 3 , BOXSIZE , BOXSIZE , BLACK ) ; // Right Direction //First arrow tft . setCursor ( 180 , 22 ) ; tft . setTextColor ( BLUE ) ; tft . setTextSize ( 3 ) ; tft . println ( "-" ) ; //Second arrow tft . setCursor ( 180 , 80 ) ; tft . setTextColor ( BLUE ) ; tft . setTextSize ( 3 ) ; tft . println ( "-" ) ; //Third Arrow tft . setCursor ( 180 , 142 ) ; tft . setTextColor ( BLUE ) ; tft . setTextSize ( 3 ) ; tft . println ( "-" ) ; //Fifth arrow tft . setCursor ( 180 , 200 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 3 ) ; tft . println ( "<" ) ; //****************************************************************************************************** // TEXT ************************************************************************************************ tft . setCursor ( 70 , 22 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 1 ) ; tft . println ( "Time / Seconds" ) ; tft . setCursor ( 70 , 80 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 1 ) ; tft . println ( "Speed" ) ; tft . setCursor ( 70 , 142 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 1 ) ; tft . println ( "Lenght / Travel" ) ; tft . setCursor ( 70 , 200 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 1 ) ; tft . println ( "left/Right" ) ; tft . setCursor ( 70 , 230 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 1 ) ; tft . println ( "V. 1.0" ) ; // tft.setCursor(BOXSIZE_L+30, 23); // tft.setTextColor(WHITE); tft.setTextSize(3); // tft.println(itoa(tid/1000, buf, 10)); // Plus one second button text ************** //******************************************* // tft.setCursor(0, 100); // tft.setTextColor(GREEN); tft.setTextSize(4); // tft.println(" Pixeljunk.dk"); }

Loop.ino

void loop() { // Recently Point was renamed TSPoint in the TouchScreen library // If you are using an older version of the library, use the // commented definition instead. // Point p = ts.getPoint(); TSPoint p = ts.getPoint(); t.update(); pinMode(XP, OUTPUT); pinMode(XM, OUTPUT); pinMode(YP, OUTPUT); pinMode(YM, OUTPUT); int i; if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { // scale from 0->1023 to tft.width p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0)); p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0)); if (p.z > ts.pressureThreshhold) { Serial.print("Y = "); Serial.print(p.y); Serial.print("\tX = "); Serial.print(p.x); // \t= space Serial.print("\tPressure = "); Serial.println(p.z); delay(100); //just to slow down the readings a little bit } // Start Button if (p.y > 0 && p.y < 60 && p.x > 0 && p.x < 110) { runok = true; tft.setCursor(80, 100); tft.setTextColor(BLUE); tft.setTextSize(2); tft.println("Start"); eventid = t.every(tid, takeReading); delay(500); tft.setCursor(80, 100); tft.setTextColor(WHITE); tft.setTextSize(2); tft.println("Start"); } // Stop Button if (p.y > 0 && p.y < 60 && p.x > 110 && p.x < 224) { Serial.print("Stop"); stopall(); } // Minus seconds Button if (p.y > 170 && p.y < 230 && p.x > 0 && p.x < 50) { tft.fillRect(220, 0, BOXSIZE_S, BOXSIZE, WHITE); tft.setCursor(235, 22); tft.setTextColor(BLACK); tft.setTextSize(2); tid-=1000; tft.println(itoa(tid/1000, buf, 10)); Serial.println(tid); //delay(250); } // Plus seconds Button if (p.y > 270 && p.y < 335 && p.x > 0 && p.x < 50) { tft.fillRect(220, 0, BOXSIZE_S, BOXSIZE, WHITE); tft.setCursor(235, 22); tft.setTextColor(BLACK); tft.setTextSize(2); tid+=1000; tft.println(itoa(tid/1000, buf, 10)); Serial.println(tid); //delay(250); } // Minus speed button if (p.y > 170 && p.y < 230 && p.x > 50 && p.x < 110) { tft.fillRect(220, BOXSIZE, BOXSIZE_S, BOXSIZE, WHITE); tft.setCursor(235, 80); tft.setTextColor(BLACK); tft.setTextSize(2); stepspeed+=100; tft.println(itoa(stepspeed/100, buf, 10)); Serial.println(stepspeed); delay(250); } // Plus speed button if (p.y > 270 && p.y < 335 && p.x > 50 && p.x < 110) { tft.fillRect(220, BOXSIZE, BOXSIZE_S, BOXSIZE, WHITE); tft.setCursor(235, 80); tft.setTextColor(BLACK); tft.setTextSize(2); stepspeed-=100; tft.println(itoa(stepspeed/100, buf, 10)); Serial.println(stepspeed); delay(250); } // minus Lenght button if (p.y > 170 && p.y < 230 && p.x > 110 && p.x < 170) { tft.fillRect(220, BOXSIZE*2, BOXSIZE_S, BOXSIZE, WHITE); tft.setCursor(235, 142); tft.setTextColor(BLACK); tft.setTextSize(2); steplenght-=10; tft.println(itoa(steplenght/10, buf, 10)); Serial.println(steplenght); delay(250); } // Plus Lenght Button if (p.y > 270 && p.y < 335 && p.x > 110 && p.x < 170) { tft.fillRect(220, BOXSIZE*2, BOXSIZE_S, BOXSIZE, WHITE); tft.setCursor(235, 142); tft.setTextColor(BLACK); tft.setTextSize(2); steplenght+=10; tft.println(itoa(steplenght/10, buf, 10)); Serial.println(steplenght); delay(250); } // Right Button if (p.y > 170 && p.y < 230 && p.x > 170 && p.x < 230) { tft.fillRect(220, BOXSIZE*3, BOXSIZE_S, BOXSIZE, WHITE); tft.setCursor(235, 200); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("R"); stepdirection=HIGH; Serial.print("Right"); Serial.print(stepdirection); } // Left Button if (p.y > 270 && p.y < 335 && p.x > 170 && p.x < 230) { tft.fillRect(220, BOXSIZE*3, BOXSIZE_S, BOXSIZE, WHITE); tft.setCursor(235, 200); tft.setTextColor(BLACK); tft.setTextSize(2); tft.println("L"); stepdirection=LOW; Serial.print("Right"); Serial.print(stepdirection); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 void loop ( ) { // Recently Point was renamed TSPoint in the TouchScreen library // If you are using an older version of the library, use the // commented definition instead. // Point p = ts.getPoint(); TSPoint p = ts . getPoint ( ) ; t . update ( ) ; pinMode ( XP , OUTPUT ) ; pinMode ( XM , OUTPUT ) ; pinMode ( YP , OUTPUT ) ; pinMode ( YM , OUTPUT ) ; int i ; if ( p . z > MINPRESSURE && p . z < MAXPRESSURE ) { // scale from 0->1023 to tft.width p . x = tft . width ( ) - ( map ( p . x , TS_MINX , TS_MAXX , tft . width ( ) , 0 ) ) ; p . y = tft . height ( ) - ( map ( p . y , TS_MINY , TS_MAXY , tft . height ( ) , 0 ) ) ; if ( p . z > ts . pressureThreshhold ) { Serial . print ( "Y = " ) ; Serial . print ( p . y ) ; Serial . print ( "\tX = " ) ; Serial . print ( p . x ) ; // \t= space Serial . print ( "\tPressure = " ) ; Serial . println ( p . z ) ; delay ( 100 ) ; //just to slow down the readings a little bit } // Start Button if ( p . y > 0 && p . y < 60 && p . x > 0 && p . x < 110 ) { runok = true ; tft . setCursor ( 80 , 100 ) ; tft . setTextColor ( BLUE ) ; tft . setTextSize ( 2 ) ; tft . println ( "Start" ) ; eventid = t . every ( tid , takeReading ) ; delay ( 500 ) ; tft . setCursor ( 80 , 100 ) ; tft . setTextColor ( WHITE ) ; tft . setTextSize ( 2 ) ; tft . println ( "Start" ) ; } // Stop Button if ( p . y > 0 && p . y < 60 && p . x > 110 && p . x < 224 ) { Serial . print ( "Stop" ) ; stopall ( ) ; } // Minus seconds Button if ( p . y > 170 && p . y < 230 && p . x > 0 && p . x < 50 ) { tft . fillRect ( 220 , 0 , BOXSIZE_S , BOXSIZE , WHITE ) ; tft . setCursor ( 235 , 22 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tid -= 1000 ; tft . println ( itoa ( tid / 1000 , buf , 10 ) ) ; Serial . println ( tid ) ; //delay(250); } // Plus seconds Button if ( p . y > 270 && p . y < 335 && p . x > 0 && p . x < 50 ) { tft . fillRect ( 220 , 0 , BOXSIZE_S , BOXSIZE , WHITE ) ; tft . setCursor ( 235 , 22 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tid += 1000 ; tft . println ( itoa ( tid / 1000 , buf , 10 ) ) ; Serial . println ( tid ) ; //delay(250); } // Minus speed button if ( p . y > 170 && p . y < 230 && p . x > 50 && p . x < 110 ) { tft . fillRect ( 220 , BOXSIZE , BOXSIZE_S , BOXSIZE , WHITE ) ; tft . setCursor ( 235 , 80 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; stepspeed += 100 ; tft . println ( itoa ( stepspeed / 100 , buf , 10 ) ) ; Serial . println ( stepspeed ) ; delay ( 250 ) ; } // Plus speed button if ( p . y > 270 && p . y < 335 && p . x > 50 && p . x < 110 ) { tft . fillRect ( 220 , BOXSIZE , BOXSIZE_S , BOXSIZE , WHITE ) ; tft . setCursor ( 235 , 80 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; stepspeed -= 100 ; tft . println ( itoa ( stepspeed / 100 , buf , 10 ) ) ; Serial . println ( stepspeed ) ; delay ( 250 ) ; } // minus Lenght button if ( p . y > 170 && p . y < 230 && p . x > 110 && p . x < 170 ) { tft . fillRect ( 220 , BOXSIZE* 2 , BOXSIZE_S , BOXSIZE , WHITE ) ; tft . setCursor ( 235 , 142 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; steplenght -= 10 ; tft . println ( itoa ( steplenght / 10 , buf , 10 ) ) ; Serial . println ( steplenght ) ; delay ( 250 ) ; } // Plus Lenght Button if ( p . y > 270 && p . y < 335 && p . x > 110 && p . x < 170 ) { tft . fillRect ( 220 , BOXSIZE* 2 , BOXSIZE_S , BOXSIZE , WHITE ) ; tft . setCursor ( 235 , 142 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; steplenght += 10 ; tft . println ( itoa ( steplenght / 10 , buf , 10 ) ) ; Serial . println ( steplenght ) ; delay ( 250 ) ; } // Right Button if ( p . y > 170 && p . y < 230 && p . x > 170 && p . x < 230 ) { tft . fillRect ( 220 , BOXSIZE* 3 , BOXSIZE_S , BOXSIZE , WHITE ) ; tft . setCursor ( 235 , 200 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "R" ) ; stepdirection = HIGH ; Serial . print ( "Right" ) ; Serial . print ( stepdirection ) ; } // Left Button if ( p . y > 270 && p . y < 335 && p . x > 170 && p . x < 230 ) { tft . fillRect ( 220 , BOXSIZE* 3 , BOXSIZE_S , BOXSIZE , WHITE ) ; tft . setCursor ( 235 , 200 ) ; tft . setTextColor ( BLACK ) ; tft . setTextSize ( 2 ) ; tft . println ( "L" ) ; stepdirection = LOW ; Serial . print ( "Right" ) ; Serial . print ( stepdirection ) ; } } }

Setup.ino

void setup() { Serial.begin(9600); Serial.println(F("TFT LCD test")); pinMode(dirpin, OUTPUT); pinMode(steppin, OUTPUT); pinMode(pin02, OUTPUT); digitalWrite(pin02, HIGH); tft.reset(); uint16_t identifier = tft.readID(); Serial.print(F("LCD driver chip: ")); Serial.println(identifier, HEX); tft.begin(identifier); tft.setRotation(1); Text(); InitialiseIO(); InitialiseInterrupt(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 void setup ( ) { Serial . begin ( 9600 ) ; Serial . println ( F ( "TFT LCD test" ) ) ; pinMode ( dirpin , OUTPUT ) ; pinMode ( steppin , OUTPUT ) ; pinMode ( pin02 , OUTPUT ) ; digitalWrite ( pin02 , HIGH ) ; tft . reset ( ) ; uint16_t identifier = tft . readID ( ) ; Serial . print ( F ( "LCD driver chip: " ) ) ; Serial . println ( identifier , HEX ) ; tft . begin ( identifier ) ; tft . setRotation ( 1 ) ; Text ( ) ; InitialiseIO ( ) ; InitialiseInterrupt ( ) ; }

You can download them here in a rar file.

Camera_slider

Libraries i use is.

http://srmonk.blogspot.com/2012/01/arduino-timer-library.html

SWTFT-Shield

https://github.com/ehubin/Adafruit-GFX-Library

Touch-Screen-Library-master

I am working on a new version, but at the moment it is far away from finished.

I hope this can help someone 🙂 Please leave a comment if you have any suggestion or correction to the code, or want to help build the new version for the camera slider