Advertisement
ThePhilleBoy

Camera dolly

Sep 14th, 2012
9,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. /*
  2. LCD screen for motorized camera dolly
  3. Code written by: Philip Sorri
  4. */
  5.  
  6. #include <LiquidCrystal.h> //LCD library
  7. #include <Bounce.h> //debounce library
  8. int button3 = 6; //button pins
  9. int button2 = 7;
  10. int button1 = 8;
  11. int startStop = 9;
  12. int runTime1;
  13. int show = 1; //what menu to show
  14. int dollySpeedNum = 0; //number of the speed
  15. int delayTime = 100; //delay after pressedbutton (see the functions)
  16. int delayDolly = 0; //delay before running
  17. int runTime = 0; //time to run after delay
  18. int motorPin = 10;
  19. int val4;
  20. int shutter = 1;
  21. int shutterCount = 0;
  22. int shutterVal = 0;
  23. Bounce bouncer1 = Bounce(button1, 15); //deblounce (button, milliseconds)
  24. Bounce bouncer2 = Bounce(button2, 15);
  25. Bounce bouncer3 = Bounce(button3, 15);
  26. Bounce bouncer4 = Bounce(startStop, 15);
  27.  
  28. LiquidCrystal lcd(12,11,5,4,3,2); //pins of the LCD to arduino
  29.  
  30. void setup() {
  31. pinMode(button1, INPUT); //button as inputs
  32. pinMode(button2, INPUT);
  33. pinMode(button3, INPUT);
  34. pinMode(startStop, INPUT);
  35. pinMode(motorPin, OUTPUT);
  36. pinMode(shutter, OUTPUT);
  37. lcd.begin(16,2);
  38. lcd.setCursor(0,0);
  39. lcd.print("DOLLYDUINO V 1.1");
  40. lcd.setCursor(0,1);
  41. lcd.print("By ThePhilleBoy");
  42. delay(3000);
  43. }
  44.  
  45. void loop() {
  46. if(shutterVal > 1) {
  47. shutterVal = 0;
  48. }
  49.  
  50. runTime1 = runTime;
  51. if(runTime == 0) {
  52. runTime1 = 10;
  53. }
  54. else {
  55. runTime1 = runTime;
  56. }
  57. bouncer1.update(); //update the buttons
  58. bouncer2.update();
  59. bouncer3.update();
  60. bouncer4.update();
  61. int val1 = bouncer1.read(); //reads the value
  62. int val2 = bouncer2.read(); //and sets the new variables to it
  63. int val3 = bouncer3.read(); //So if button is pressed value = HIGH
  64. val4 = bouncer4.read();
  65.  
  66. if (show > 4) { //Number of menus
  67. show = 1;
  68. }
  69. if(val3 == HIGH) { //scroll through the different menus
  70. show = show + 1; //the show number indicates which menu we're in
  71. delay(delayTime * 5);
  72. }
  73. if(show == 1) { //if show is 1 the dollySpeed function is chosen/shown
  74. dollySpeed(val1, val2); //To change values in this menu with same buttons
  75. } //in all the menus
  76. else if(show == 2) { //if show is 2 delay function is chosen/shown on LCD
  77. dollyDelay(val1, val2);
  78. }
  79. else if(show == 3) {
  80. runningTime(val1, val2);
  81. }
  82. else if(show == 4) { //shows all the setting that are chosen
  83. settings();
  84. if(val1 == HIGH || val2 == HIGH) {
  85. shutterVal = shutterVal + 1;
  86. delay(delayTime*3);
  87. }
  88. }
  89.  
  90. if(val4 == HIGH && shutterVal == 0){
  91. motorOn();
  92. }
  93. if(val4 == LOW){
  94. analogWrite(motorPin, LOW);
  95. }
  96. if(val4 == HIGH && shutterVal == 1) {
  97. motorOn();
  98. lcd.setCursor(0,0);
  99. lcd.print("P:");
  100. lcd.setCursor(4,0);
  101. lcd.print(shutterCount);
  102. }
  103. }
  104.  
  105. void dollySpeed(int num1, int num2) {
  106. lcd.setCursor(0,0); //sets the startpoint of the text to (0,0)
  107. lcd.print("Dolly speed: "); //Writes "Dolly speed:" to the LCD
  108. if(num1 == HIGH) { //if num1 which is val1/button1 is pressed the speed
  109. dollySpeedNum = dollySpeedNum + 1; //increases with 1
  110. delay(delayTime); //delay before next press, otherwise it would
  111. } //scroll fast as hell
  112. if(num2 == HIGH) { //if button2 is pressed decrease with 1
  113. dollySpeedNum = dollySpeedNum - 1;
  114. delay(delayTime);
  115. }
  116. lcd.setCursor(0,1); //sets the starting point of the print
  117. lcd.print(dollySpeedNum); //prints to the start point (0,1)
  118. if(dollySpeedNum < 10) {
  119. lcd.setCursor(1, 1);
  120. lcd.print("% "); //makes a percent sign after the number
  121. } //the space after it is to hide numbers that might
  122. if(dollySpeedNum >= 10 && dollySpeedNum < 100) { //be shown from the last
  123. lcd.setCursor(2, 1); //menu that we scrolled from.
  124. lcd.print("% "); //if the speed if over 10 and less than 100 it moves
  125. } //the percentsign one step to the right.
  126. if(dollySpeedNum == 100) { //same here
  127. lcd.setCursor(3, 1);
  128. lcd.print("% ");
  129. }
  130. if(dollySpeedNum > 100) { //I wanted the speed to be in percent so I
  131. dollySpeedNum = 0; //have to limit the value of dollySpeedNum.
  132. } //if the value is higher than 100 it makes it to 0
  133. if(dollySpeedNum < 0) { //and if it's lower than 0 it goes to 100.
  134. dollySpeedNum = 100;
  135. }
  136. }
  137.  
  138. void dollyDelay(int but1, int but2) {
  139. int decimal;
  140. decimal = delayDolly%10;
  141. lcd.setCursor(0,0);
  142. lcd.print("Delay: ");
  143. if(but1 == HIGH) {
  144. delayDolly = delayDolly + 1;
  145. delay(delayTime);
  146. }
  147. if(but2 == HIGH) {
  148. delayDolly = delayDolly - 1;
  149. delay(delayTime);
  150. }
  151. lcd.setCursor(0,1);
  152. lcd.print(delayDolly/10);
  153. if(delayDolly < 10) {
  154. lcd.setCursor(1, 1);
  155. lcd.print(".");
  156. lcd.setCursor(2,1);
  157. lcd.print(decimal);
  158. lcd.setCursor(3,1);
  159. lcd.print(" s ");
  160. }
  161. if(delayDolly >= 10 && delayDolly < 100) {
  162. lcd.setCursor(1, 1);
  163. lcd.print(".");
  164. lcd.setCursor(2,1);
  165. lcd.print(decimal);
  166. lcd.setCursor(3,1);
  167. lcd.print(" s ");
  168. }
  169. if(delayDolly > 99) {
  170. lcd.setCursor(2, 1);
  171. lcd.print(".");
  172. lcd.setCursor(3,1);
  173. lcd.print(decimal);
  174. lcd.setCursor(4,1);
  175. lcd.print(" s ");
  176. }
  177. if(delayDolly > 999) {
  178. delayDolly = 0;
  179. }
  180. if(delayDolly < 0) {
  181. delayDolly = 999;
  182. }
  183. }
  184.  
  185. void runningTime(int num1, int num2) {
  186. int decimal1;
  187. decimal1 = runTime%10;
  188. lcd.setCursor(0,0);
  189. lcd.print("Run time: ");
  190. if(num1 == HIGH) {
  191. runTime = runTime + 1;
  192. delay(delayTime);
  193. }
  194. if(num2 == HIGH) {
  195. runTime = runTime - 1;
  196. delay(delayTime);
  197. }
  198. lcd.setCursor(0,1);
  199. lcd.print(runTime/10);
  200. if(runTime < 10) {
  201. lcd.setCursor(1, 1);
  202. lcd.print(".");
  203. lcd.setCursor(2,1);
  204. lcd.print(decimal1);
  205. lcd.setCursor(3,1);
  206. lcd.print(" s ");
  207. }
  208. if(runTime >= 10 && runTime < 100) {
  209. lcd.setCursor(1, 1);
  210. lcd.print(".");
  211. lcd.setCursor(2,1);
  212. lcd.print(decimal1);
  213. lcd.setCursor(3,1);
  214. lcd.print(" s ");
  215. }
  216. if(runTime > 99) {
  217. lcd.setCursor(2, 1);
  218. lcd.print(".");
  219. lcd.setCursor(3,1);
  220. lcd.print(decimal1);
  221. lcd.setCursor(4,1);
  222. lcd.print(" s ");
  223. }
  224. if(runTime > 999) {
  225. runTime = 0;
  226. }
  227. if(runTime < 0) {
  228. runTime = 999;
  229. }
  230. }
  231.  
  232. void settings() {
  233. int decimal1;
  234. int decimal2;
  235. decimal1 = runTime%10;
  236. decimal2 = delayTime%10;
  237. lcd.setCursor(0,0);
  238. lcd.print("S: ");
  239. lcd.setCursor(3,0);
  240. lcd.print(dollySpeedNum);
  241. if(dollySpeedNum < 10) {
  242. lcd.setCursor(4,0);
  243. lcd.print("% ");
  244. }
  245. if(dollySpeedNum >= 10 && dollySpeedNum < 100) {
  246. lcd.setCursor(5,0);
  247. lcd.print("% ");
  248. }
  249. if(dollySpeedNum == 100) {
  250. lcd.setCursor(6,0);
  251. lcd.print("% ");
  252. }
  253.  
  254. lcd.setCursor(8,0);
  255. lcd.print("R: ");
  256. lcd.setCursor(11,0);
  257. lcd.print(runTime/10);
  258. if(runTime < 10) {
  259. lcd.setCursor(12, 0);
  260. lcd.print(".");
  261. lcd.setCursor(13,0);
  262. lcd.print(decimal1);
  263. lcd.setCursor(14,0);
  264. lcd.print("s");
  265. }
  266. if(runTime >= 10 && runTime < 100) {
  267. lcd.setCursor(12,0);
  268. lcd.print(".");
  269. lcd.setCursor(13,0);
  270. lcd.print(decimal1);
  271. lcd.setCursor(14,0);
  272. lcd.print("s");
  273. }
  274. if(runTime > 99) {
  275. lcd.setCursor(13,0);
  276. lcd.print(".");
  277. lcd.setCursor(14,0);
  278. lcd.print(decimal1);
  279. lcd.setCursor(15,0);
  280. lcd.print("s");
  281. }
  282.  
  283. lcd.setCursor(0,1);
  284. lcd.print("D: ");
  285. lcd.setCursor(3,1);
  286. lcd.print(delayDolly/10);
  287. if(delayDolly < 10) {
  288. lcd.setCursor(4, 1);
  289. lcd.print(".");
  290. lcd.setCursor(5,1);
  291. lcd.print(decimal1);
  292. lcd.setCursor(6,1);
  293. lcd.print("s");
  294. }
  295. if(delayDolly >= 10 && delayDolly < 100) {
  296. lcd.setCursor(4,1);
  297. lcd.print(".");
  298. lcd.setCursor(5,1);
  299. lcd.print(decimal2);
  300. lcd.setCursor(6,1);
  301. lcd.print("s");
  302. }
  303. if(delayDolly > 99) {
  304. lcd.setCursor(5, 1);
  305. lcd.print(".");
  306. lcd.setCursor(6,1);
  307. lcd.print(decimal1);
  308. lcd.setCursor(7,1);
  309. lcd.print("s");
  310. }
  311. if(val4 == LOW) {
  312. if(shutterVal == 0) {
  313. lcd.setCursor(10,1);
  314. lcd.print("I=OFF");
  315. }
  316. if(shutterVal == 1) {
  317. lcd.setCursor(10,1);
  318. lcd.print("I=ON ");
  319. }
  320. }
  321. }
  322.  
  323. void motorOn () {
  324. int speedValue = map(dollySpeedNum, 0, 100, 0, 255);
  325. analogWrite(motorPin, speedValue);
  326. delay(runTime1*100);
  327. if(delayDolly > 0) {
  328. analogWrite(motorPin, LOW);
  329. picture();
  330. shutterCount = shutterCount + 1;
  331. delay(delayDolly*100);
  332. }
  333. }
  334.  
  335. void picture() {
  336. pinMode(shutter, HIGH);
  337. delay(50);
  338. pinMode(shutter, LOW);
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement