PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/SloMomBox/SloMomBox.ino

https://bitbucket.org/ionutcotoi/slomomentscontrolbox
C++ | 809 lines | 623 code | 119 blank | 67 comment | 196 complexity | 65101dce1cd6c975f898b76c649a064a MD5 | raw file
Possible License(s): LGPL-2.1
  1. #include "SPI.h"
  2. #include <EEPROM.h>
  3. #include "Wire.h"
  4. #include <LiquidCrystal.h>
  5. #include <MenuBackend.h>
  6. LiquidCrystal lcd(0);
  7. String inputString = ""; // a string to hold incoming data
  8. String inputRobot = "";
  9. boolean stringComplete = false; // whether the string is complete
  10. boolean stringRobotComplete = false;
  11. int l;
  12. byte address = 0x11;
  13. int CSS= 49;
  14. int i=0;
  15. unsigned analogSensorsTotal = 16;
  16. unsigned analogIn[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};
  17. unsigned analogVal[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  18. unsigned digitalIn[] = {22, 24, 26, 28, 30, 32, 34, 36};
  19. unsigned digitalOut[] = {23, 25, 27, 29, 31, 33, 35, 37};
  20. unsigned digitalVal[] = {0, 0, 0, 0, 0, 0, 0, 0};
  21. unsigned keypadIn[] = {2, 3, 4, 5};
  22. int sensorPin1 = A0;
  23. int sensorPin2 = A1;
  24. int sensorPin3 = A2;
  25. int sensorPin4 = A3;
  26. int sensorPin5 = A4;
  27. int sensorPin6 = A5;
  28. int sensorPin7 = A6;
  29. int sensorPin8 = A7;
  30. int sensor1 = 0;
  31. int sensor2 = 0;
  32. int sensor3 = 0;
  33. int sensor4 = 0;
  34. int sensor5 = 0;
  35. int sensor6 = 0;
  36. int sensor7 = 0;
  37. int sensor8 = 0;
  38. #define ESC_PIN 2
  39. #define KB_PIN 3
  40. #define DOWN_PIN 4
  41. #define UP_PIN 5
  42. #define pinEstop 7
  43. #define pinBuzzer 12
  44. #define txSerial 18
  45. #define rxSerial 19
  46. #define sdaLcd 20
  47. #define sclLcd 21
  48. #define soundActive tone(pinBuzzer, 2000, 200)
  49. #define noSound noTone(pinBuzzer)
  50. int lastButtonPushed = 0;
  51. int lastButtonEnterState = LOW;
  52. int lastButtonEscState = LOW;
  53. int lastButtonLeftState = LOW;
  54. int lastButtonRightState = LOW;
  55. long lastEnterDebounceTime = 0;
  56. long lastEscDebounceTime = 0;
  57. long lastLeftDebounceTime = 0;
  58. long lastRightDebounceTime = 0;
  59. long debounceDelay = 100;
  60. bool menurefreshed = true;
  61. MenuBackend menu = MenuBackend(menuUsed,menuChanged);
  62. MenuItem miAnalog = MenuItem("Analog sens");
  63. MenuItem miASens1 = MenuItem(">");
  64. MenuItem miASens2 = MenuItem("<");
  65. MenuItem miDigital = MenuItem("Digital sens");
  66. MenuItem miDSens1 = MenuItem(">");
  67. MenuItem miDSens2 = MenuItem("<");
  68. MenuItem miSound = MenuItem("Sound");
  69. MenuItem miOn = MenuItem("on");
  70. MenuItem miOff = MenuItem("off");
  71. int totalF1 = 0;
  72. int readingsF1[10];
  73. int indexF1 = 0;
  74. int averageF1 = 0;
  75. int valoriF1[100];
  76. int indexvalF1 = 0;
  77. int val_ant1;
  78. void setup() {
  79. initialise_pins();
  80. initialise_features();
  81. //initialiseAnalogTune();
  82. for (int thisReadingF1 = 0; thisReadingF1 < 10; thisReadingF1++)
  83. readingsF1[thisReadingF1] = 0;
  84. Serial.begin(115200);
  85. Serial1.begin(115200);
  86. pinMode (CSS, OUTPUT);
  87. SPI.begin();
  88. // reserve 200 bytes for the inputString:
  89. inputString.reserve(30);
  90. Serial.println("OK");
  91. Serial1.println("ROBOT INTF OK");
  92. lcd_default();
  93. }
  94. #define CMD_LEN 4
  95. #define FRAME_START_ADDR 1000
  96. #define BLENDER_FPS_ADDR 0
  97. #define BNUM_FRAMES_ADDR 10
  98. int value = 0;
  99. int numFrames = 0;
  100. int frame = 0;
  101. char cmd[CMD_LEN+1] = {0};
  102. char cmdRobot[CMD_LEN+1] = {0};
  103. char charBuf[50];
  104. char charBufRobot[50];
  105. void loop() {
  106. if(stringRobotComplete) {
  107. Serial.println(inputRobot);
  108. memset(cmdRobot, 0, sizeof(cmd));
  109. inputRobot.toCharArray(charBufRobot, 50) ;
  110. strncpy(cmdRobot, charBufRobot, CMD_LEN);
  111. if(strcmp(cmdRobot, "RRUN") == 0) {
  112. Serial.println("Robot: RRUN");
  113. runProgram();
  114. } else if (strcmp(cmdRobot, "INIT") == 0) {
  115. digitalPotWrite(CSS, EEPROM.read(FRAME_START_ADDR));
  116. Serial.println("Robot: INIT");
  117. }
  118. inputRobot = "";
  119. stringRobotComplete = false;
  120. }
  121. if(stringComplete) {
  122. memset(cmd, 0, sizeof(cmd));
  123. //Serial.print("STRING: ");
  124. //Serial.println(inputString);
  125. inputString.toCharArray(charBuf, 50) ;
  126. if(charBuf[0] == 'F') {
  127. strncpy(cmd, charBuf+2, CMD_LEN);
  128. //Serial.print("CMD: ");
  129. //Serial.println(cmd);
  130. if(strcmp(cmd, "MOVE") == 0) {
  131. // MOVE command
  132. value = atoi(charBuf+4);
  133. if(value < 0)
  134. value = 0;
  135. if(value > 255)
  136. value = 255;
  137. digitalPotWrite(CSS, value);
  138. } else if(strcmp(cmd, "STOR") == 0) {
  139. // STORe focus point
  140. // STOR addr focusVal
  141. frame = atoi(charBuf+4);
  142. //Serial.print("FRAME: ");
  143. //Serial.println(frame, DEC);
  144. value = atoi(charBuf+9);
  145. if(value > 255)
  146. value = 255;
  147. if(value < 0)
  148. value = 0;
  149. //Serial.print("VALUE: ");
  150. //Serial.println(value, DEC);
  151. EEPROM.write(FRAME_START_ADDR + frame, value);
  152. Serial.println("OK");
  153. } else if(strcmp(cmd, "BFPS") == 0) {
  154. // BFPS - blender frames per second
  155. // BFPS fpsVal numFrames
  156. value = atoi(charBuf+4);
  157. if(value > 255)
  158. value = 255;
  159. if(value < 0)
  160. value = 0;
  161. EEPROM.write(BLENDER_FPS_ADDR, value);
  162. value = atoi(charBuf + 9);
  163. if(value > 255)
  164. value = 255;
  165. if(value < 0)
  166. value = 0;
  167. EEPROM.write(BNUM_FRAMES_ADDR, value);
  168. Serial.print("FRAMES: ");
  169. Serial.println(EEPROM.read(BNUM_FRAMES_ADDR), DEC);
  170. Serial.print("FPS: ");
  171. Serial.println(EEPROM.read(BLENDER_FPS_ADDR), DEC);
  172. } else if(strcmp(cmd, "RRUN") == 0) {
  173. // RUN program
  174. runProgram();
  175. } else if(strcmp(cmd, "STOP") == 0) {
  176. // STOP program
  177. // This cannot be done here
  178. } else if(strcmp(cmd, "SHOW") == 0) {
  179. displayProgram();
  180. } else if(strcmp(cmd, "CLER") == 0) {
  181. Serial.print("ERASING..");
  182. for(int i=0; i<2000; i++) {
  183. if(i%500 == 0)
  184. Serial.print(".");
  185. EEPROM.write(i, 0);
  186. }
  187. Serial.println("DONE");
  188. } else{
  189. // Unknown command
  190. Serial.println("ERR: Unknown command");
  191. }
  192. } else if(charBuf[0] == 'D') {
  193. int output;
  194. } else if(charBuf[0] == 'A') {
  195. int output = -1;
  196. output = atoi(charBuf+1);
  197. Serial.println(output, DEC);
  198. char *tmpBuf = charBuf+3;
  199. strncpy(cmd, tmpBuf, CMD_LEN);
  200. Serial.println(cmd);
  201. if(strcmp(cmd, "MOVE") == 0) {
  202. // MOVE command
  203. value = atoi(tmpBuf+4);
  204. if(value < 0)
  205. value = 0;
  206. if(value > 255)
  207. value = 255;
  208. digitalPotWrite(CSS, value);
  209. } else if(strcmp(cmd, "STOR") == 0) {
  210. // STORe focus point
  211. // STOR addr focusVal
  212. frame = atoi(tmpBuf+4);
  213. //Serial.print("FRAME: ");
  214. //Serial.println(frame, DEC);
  215. value = atoi(tmpBuf+9);
  216. if(value > 255)
  217. value = 255;
  218. if(value < 0)
  219. value = 0;
  220. //Serial.print("VALUE: ");
  221. //Serial.println(value, DEC);
  222. EEPROM.write(FRAME_START_ADDR + frame, value);
  223. Serial.println("OK");
  224. } else if(strcmp(cmd, "BFPS") == 0) {
  225. // BFPS - blender frames per second
  226. // BFPS fpsVal numFrames
  227. value = atoi(tmpBuf+4);
  228. if(value > 255)
  229. value = 255;
  230. if(value < 0)
  231. value = 0;
  232. EEPROM.write(BLENDER_FPS_ADDR, value);
  233. value = atoi(tmpBuf + 9);
  234. if(value > 255)
  235. value = 255;
  236. if(value < 0)
  237. value = 0;
  238. EEPROM.write(BNUM_FRAMES_ADDR, value);
  239. Serial.print("FRAMES: ");
  240. Serial.println(EEPROM.read(BNUM_FRAMES_ADDR), DEC);
  241. Serial.print("FPS: ");
  242. Serial.println(EEPROM.read(BLENDER_FPS_ADDR), DEC);
  243. } else if(strcmp(cmd, "RRUN") == 0) {
  244. // RUN program
  245. runProgram();
  246. } else if(strcmp(cmd, "STOP") == 0) {
  247. // STOP program
  248. // This cannot be done here
  249. } else if(strcmp(cmd, "SHOW") == 0) {
  250. displayProgram();
  251. } else if(strcmp(cmd, "CLER") == 0) {
  252. Serial.print("ERASING..");
  253. for(int i=0; i<2000; i++) {
  254. if(i%500 == 0)
  255. Serial.print(".");
  256. EEPROM.write(i, 0);
  257. }
  258. Serial.println("DONE");
  259. } else{
  260. // Unknown command
  261. Serial.println("ERR: Unknown command");
  262. }
  263. }
  264. inputString = "";
  265. stringComplete = false;
  266. }
  267. if(emergencyStop() == '0'){
  268. //readPins();
  269. display_refresh();
  270. //serial_write();
  271. readButtons();
  272. navigateMenus();
  273. noTone(pinBuzzer);
  274. //processAnalogInputs();
  275. if (!menurefreshed){
  276. lcd_default();
  277. }
  278. }else{
  279. alarm();
  280. }
  281. }
  282. // Run the stored points in EEPROM according to the fps
  283. void runProgram() {
  284. int frameDelay=1000/EEPROM.read(BLENDER_FPS_ADDR);
  285. int i=0;
  286. int numFrames = EEPROM.read(BNUM_FRAMES_ADDR);
  287. Serial.print("DELAY: ");
  288. Serial.println(frameDelay, DEC);
  289. for(i = 0; i<numFrames; i++) {
  290. value = EEPROM.read(FRAME_START_ADDR+i);
  291. digitalPotWrite(CSS, value);
  292. delay(frameDelay);
  293. Serial.print("GOTO: ");
  294. Serial.println(value);
  295. // TODO Check ESTOP signal
  296. // TODO Check serial STOP
  297. }
  298. }
  299. void displayProgram() {
  300. int numFrames = EEPROM.read(BNUM_FRAMES_ADDR);
  301. int fps = EEPROM.read(BLENDER_FPS_ADDR);
  302. int frameDelay=1000/fps; // 1000 ms/fps
  303. Serial.print("FRAMES: ");
  304. Serial.println(numFrames);
  305. Serial.print("FPS: ");
  306. Serial.println(fps, DEC);
  307. Serial.print("DELAY: ");
  308. Serial.println(frameDelay, DEC);
  309. Serial.println("BEGIN");
  310. for(int i=0; i<numFrames; i++) {
  311. int val = EEPROM.read(FRAME_START_ADDR + i);
  312. Serial.print("FOCUS POINT: ");
  313. Serial.println(val, DEC);
  314. }
  315. Serial.println("END");
  316. }
  317. // This receives data on interrupt from the serial port
  318. void serialEvent() {
  319. while (Serial.available()) {
  320. // get the new byte:
  321. char inChar = (char)Serial.read();
  322. Serial1.print(inChar);
  323. // add it to the inputString:
  324. inputString += inChar;
  325. // if the incoming character is a newline, set a flag
  326. // so the main loop can do something about it:
  327. if ((inChar == '\n') || (inChar == '\r')) {
  328. stringComplete = true;
  329. }
  330. }
  331. }
  332. void serialEvent1() {
  333. while (Serial1.available()) {
  334. // get the new byte:
  335. char inChar = (char)Serial1.read();
  336. // add it to the inputString:
  337. inputRobot += inChar;
  338. // if the incoming character is a newline, set a flag
  339. // so the main loop can do something about it:
  340. if ((inChar == '\n') || (inChar == '\r')) {
  341. stringRobotComplete = true;
  342. }
  343. }
  344. }
  345. int digitalPotWrite(int l, int value) {
  346. digitalWrite(l, LOW);
  347. SPI.transfer(address);
  348. SPI.transfer(value);
  349. Serial.println(value);
  350. digitalWrite(l, HIGH);
  351. }
  352. void initialise_pins(){
  353. pinMode(A0, INPUT_PULLUP);
  354. pinMode(A1, INPUT_PULLUP);
  355. pinMode(A2, INPUT_PULLUP);
  356. pinMode(A3, INPUT_PULLUP);
  357. pinMode(A4, INPUT_PULLUP);
  358. pinMode(A5, INPUT_PULLUP);
  359. pinMode(A6, INPUT_PULLUP);
  360. pinMode(A7, INPUT_PULLUP);
  361. pinMode(A8, INPUT_PULLUP);
  362. pinMode(A9, INPUT_PULLUP);
  363. pinMode(A10, INPUT_PULLUP);
  364. pinMode(A11, INPUT_PULLUP);
  365. pinMode(A12, INPUT_PULLUP);
  366. pinMode(A13, INPUT_PULLUP);
  367. pinMode(A14, INPUT_PULLUP);
  368. pinMode(A15, INPUT_PULLUP);
  369. pinMode(UP_PIN, INPUT_PULLUP);
  370. pinMode(DOWN_PIN, INPUT_PULLUP);
  371. pinMode(KB_PIN, INPUT_PULLUP);
  372. pinMode(ESC_PIN, INPUT_PULLUP);
  373. }
  374. void initialise_features(){
  375. //Serial communication with the laptop
  376. Serial.begin(9600);
  377. Serial.println("Starting...");
  378. //tone start
  379. tone(pinBuzzer, 2000, 200);
  380. // set up the LCD's number of columns and rows:
  381. //LCD init
  382. lcd.begin(16, 2);
  383. //EStop init
  384. initialiseEStop();
  385. //Initialise Menu
  386. menu.getRoot().add(miAnalog);
  387. miAnalog.addRight(miDigital).addRight(miSound);
  388. miAnalog.add(miASens1).addRight(miASens2);
  389. miDigital.add(miDSens1).addRight(miDSens2);
  390. miSound.add(miOn).addRight(miOff);
  391. menu.toRoot();
  392. lcd_default();
  393. }
  394. void readPins(){
  395. for(int i=0; i<=analogSensorsTotal; i++){
  396. //analogVal[i] = analogRead(analogIn[i]);
  397. //Serial.println(analogVal[i]);
  398. }
  399. //Serial.println(digitalRead(7));
  400. if(analogRead(A2)<20){
  401. //lcd.print("Laser triggered");
  402. //Serial.println("Laser triggered");
  403. }else{
  404. //lcd.print("Ready!");
  405. //Serial.println("ready");
  406. }
  407. }
  408. void display_refresh(){
  409. }
  410. void serial_write(){
  411. }
  412. void menuChanged(MenuChangeEvent changed){
  413. MenuItem newMenuItem=changed.to; //get the destination menu
  414. lcd.setCursor(0,0);
  415. if(newMenuItem.getName()==menu.getRoot()){
  416. lcd_default();
  417. }else if(newMenuItem.getName()=="Analog sens"){
  418. lcd.print(" Analog sens ");
  419. }else if(newMenuItem.getName()==">"){
  420. lcd.print(" -> ");
  421. }else if(newMenuItem.getName()=="<"){
  422. lcd.print(" <- ");
  423. }else if(newMenuItem.getName()=="Digital sens"){
  424. lcd.print(" Digital Sens ");
  425. }else if(newMenuItem.getName()==">"){
  426. lcd.print(" -> ");
  427. }else if(newMenuItem.getName()=="<"){
  428. lcd.print(" <- ");
  429. }else if(newMenuItem.getName()=="Sound"){
  430. lcd.print(" Sound ");
  431. }else if(newMenuItem.getName()=="on"){
  432. lcd.print(" on ");
  433. EEPROM.write(3,1);
  434. }else if(newMenuItem.getName()=="off"){
  435. lcd.print(" off ");
  436. EEPROM.write(3,0);
  437. }
  438. }
  439. void menuUsed(MenuUseEvent used){
  440. lcd.setCursor(0,0);
  441. lcd.print("You used ");
  442. //lcd.setCursor(0,1);
  443. //lcd.print(used.item.getName());
  444. delay(3000);
  445. // lcd.setCursor(0,0);
  446. // lcd.print("Settings ");
  447. menu.toRoot();
  448. lcd_default();
  449. }
  450. void readButtons(){ //read buttons status
  451. int reading;
  452. int buttonEnterState=HIGH;
  453. int buttonEscState=HIGH;
  454. int buttonLeftState=HIGH;
  455. int buttonRightState=HIGH;
  456. reading = digitalRead(KB_PIN);
  457. if (reading != lastButtonEnterState) {
  458. lastEnterDebounceTime = millis();
  459. }
  460. if ((millis() - lastEnterDebounceTime) > debounceDelay) {
  461. buttonEnterState=reading;
  462. lastEnterDebounceTime=millis();
  463. }
  464. lastButtonEnterState = reading;
  465. reading = digitalRead(ESC_PIN);
  466. if (reading != lastButtonEscState) {
  467. lastEscDebounceTime = millis();
  468. }
  469. if ((millis() - lastEscDebounceTime) > debounceDelay) {
  470. buttonEscState = reading;
  471. lastEscDebounceTime=millis();
  472. }
  473. lastButtonEscState = reading;
  474. reading = digitalRead(DOWN_PIN);
  475. if (reading != lastButtonRightState) {
  476. lastRightDebounceTime = millis();
  477. }
  478. if ((millis() - lastRightDebounceTime) > debounceDelay) {
  479. buttonRightState = reading;
  480. lastRightDebounceTime =millis();
  481. }
  482. lastButtonRightState = reading;
  483. reading = digitalRead(UP_PIN);
  484. if (reading != lastButtonLeftState) {
  485. lastLeftDebounceTime = millis();
  486. }
  487. if ((millis() - lastLeftDebounceTime) > debounceDelay) {
  488. buttonLeftState = reading;
  489. lastLeftDebounceTime=millis();;
  490. }
  491. lastButtonLeftState = reading;
  492. if (buttonEnterState==LOW){
  493. lastButtonPushed=KB_PIN;
  494. }else if(buttonEscState==LOW){
  495. lastButtonPushed=ESC_PIN;
  496. }else if(buttonRightState==LOW){
  497. lastButtonPushed=DOWN_PIN;
  498. }else if(buttonLeftState==LOW){
  499. lastButtonPushed=UP_PIN;
  500. }else{
  501. lastButtonPushed=0;
  502. }
  503. }
  504. void navigateMenus() {
  505. MenuItem currentMenu=menu.getCurrent();
  506. switch (lastButtonPushed){
  507. case KB_PIN:
  508. if(!(currentMenu.moveDown())){ //if the current menu has a child and has been pressed enter then menu navigate to item below
  509. menu.use();
  510. }else{ //otherwise, if menu has no child and has been pressed enter the current menu is used
  511. menu.moveDown();
  512. }
  513. break;
  514. case ESC_PIN:
  515. menu.toRoot();
  516. //TO DO JUMP ONE LEVEL UP menu.moveUp();
  517. break;
  518. case DOWN_PIN:
  519. menu.moveRight();
  520. break;
  521. case UP_PIN:
  522. menu.moveLeft();
  523. break;
  524. }
  525. lastButtonPushed=0;
  526. }
  527. void lcd_default(){
  528. lcd.setCursor(0,0);
  529. lcd.print("SloMoments Robo1");
  530. menurefreshed = true;
  531. lcd.setCursor(0,1);
  532. lcd.print(" ");
  533. }
  534. boolean estop = false;
  535. void initialiseEStop(){
  536. pinMode(pinEstop, INPUT_PULLUP);
  537. }
  538. char emergencyStop(){
  539. if(digitalRead(pinEstop)){
  540. estop = false;
  541. return '0';
  542. }else{
  543. estop = true;
  544. return '1';
  545. }
  546. }
  547. void alarm(){
  548. lcd.setCursor(0,0);
  549. lcd.print(" PANIC! ");
  550. lcd.setCursor(0,1);
  551. lcd.print(" EMERGENCY STOP ");
  552. tone(pinBuzzer, 5000);
  553. delay(50);
  554. tone(pinBuzzer, 1000);
  555. delay(50);
  556. }
  557. void initialiseAnalogDetection(){
  558. pinMode(A0, INPUT_PULLUP);
  559. pinMode(A1, INPUT_PULLUP);
  560. pinMode(A2, INPUT_PULLUP);
  561. pinMode(A3, INPUT_PULLUP);
  562. pinMode(A4, INPUT_PULLUP);
  563. pinMode(A5, INPUT_PULLUP);
  564. pinMode(A6, INPUT_PULLUP);
  565. pinMode(A7, INPUT_PULLUP);
  566. }
  567. char AnalogDetection(){
  568. sensor1 = analogRead(sensorPin1);
  569. sensor2 = analogRead(sensorPin2);
  570. sensor3 = analogRead(sensorPin3);
  571. sensor4 = analogRead(sensorPin4);
  572. sensor5 = analogRead(sensorPin5);
  573. sensor6 = analogRead(sensorPin6);
  574. sensor7 = analogRead(sensorPin7);
  575. sensor8 = analogRead(sensorPin8);
  576. if(sensor1 > 1000)
  577. Serial.print("not s1 - ");
  578. else
  579. Serial.print("analog1 - ");
  580. if(sensor2 > 1000)
  581. Serial.print("not s2 - ");
  582. else
  583. Serial.print("analog2 - ");
  584. if(sensor3 > 1000)
  585. Serial.print("not s3 - ");
  586. else
  587. Serial.print("analog3 - ");
  588. if(sensor4 > 1000)
  589. Serial.print("not s4 - ");
  590. else
  591. Serial.print("analog4 - ");
  592. if(sensor5 > 1000)
  593. Serial.print("not s5 - ");
  594. else
  595. Serial.print("analog5 - ");
  596. if(sensor6 > 1000)
  597. Serial.print("not s6 - ");
  598. else
  599. Serial.print("analog6 - ");
  600. if(sensor7 > 1000)
  601. Serial.print("not s7 - ");
  602. else
  603. Serial.print("analog7 - ");
  604. if(sensor8 > 1000)
  605. Serial.println("not s8");
  606. else
  607. Serial.println("analog8");
  608. }
  609. void initialiseAnalogTune(){
  610. pinMode(A8, INPUT_PULLUP);
  611. pinMode(A9, INPUT_PULLUP);
  612. pinMode(A10, INPUT_PULLUP);
  613. pinMode(A11, INPUT_PULLUP);
  614. pinMode(A12, INPUT_PULLUP);
  615. pinMode(A13, INPUT_PULLUP);
  616. pinMode(A14, INPUT_PULLUP);
  617. pinMode(A15, INPUT_PULLUP);
  618. }
  619. unsigned valori[50];
  620. unsigned indexval[] = {0,0,0,0,0,0,0,0};
  621. unsigned val_ant[] = {0,0,0,0,0,0,0,0};
  622. int id = 0;
  623. int nu = 0;
  624. char analogTune(){
  625. int F1 = analogRead(12);
  626. if ((F1 != 274) && (F1 != 273) && (F1 != 272) && (F1 != 271) && (F1 != 270) && (F1 != 269) && (F1 != 268) && (F1 != 267) && (F1 != 266) && (F1 != 265) && (F1 != 264)){
  627. F1 = abs((analogRead(12)-14)*100/262 - 100);
  628. }else{
  629. F1=0;
  630. }
  631. Serial.print(F1);
  632. Serial.print(" - ");
  633. /*----------------------ok------------------------*/
  634. int F2 = analogRead(13);
  635. if ((F2 != 265) && (F2 != 264) && (F2 != 263)){
  636. F2 = abs((analogRead(13)-19)*100/265 - 100);
  637. }else{
  638. F2=0;
  639. }
  640. Serial.print(F2);
  641. Serial.print(" - ");
  642. /*-----------------------ok-----------------------*/
  643. int F3 = analogRead(14);
  644. Serial.print(F3);
  645. Serial.print(" - ");
  646. if ((F3 != 261) && (F3 != 260) && (F3 != 259)){
  647. F3 = abs((analogRead(14)-14)*100/255 - 100);
  648. }else{
  649. F3=0;
  650. }
  651. int F4 = analogRead(15);
  652. if ((F4 != 268) && (F4 != 267) && (F4 != 266)){
  653. F4 = abs((analogRead(15)-13)*100/260 - 100);
  654. }else{
  655. F4=0;
  656. }
  657. Serial.print(F4);
  658. Serial.print(" - ");
  659. int F5 = analogRead(8);
  660. Serial.print(F5);
  661. Serial.print(" - ");
  662. if ((F5 != 268) && (F5 != 267) && (F5 != 266)){
  663. F5 = abs((analogRead(8)-13)*100/261 - 100);
  664. }else{
  665. F5=0;
  666. }
  667. int F6 = analogRead(9);
  668. Serial.print(F6);
  669. Serial.print(" - ");
  670. if ((F6 != 268) && (F6 != 267) && (F6 != 266)){
  671. F6 = abs((analogRead(9)-12)*100/256 - 100);
  672. }else{
  673. F6=0;
  674. }
  675. int F7 = analogRead(10);
  676. Serial.print(F7);
  677. Serial.print(" - ");
  678. if ((F7 != 268) && (F7 != 267) && (F7 != 266)){
  679. F7 = abs((analogRead(10)-13)*100/258 - 100);
  680. }else{
  681. F7=0;
  682. }
  683. int F8 = analogRead(11);
  684. Serial.println(F8);
  685. if ((F8 != 268) && (F8 != 267) && (F8 != 266)){
  686. F8 = abs((analogRead(11)-13)*100/256 - 100);
  687. }else{
  688. F8=0;
  689. }
  690. }