Advertisement
BimoSora

testing

Jun 29th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. LiquidCrystal_I2C lcd(0x27,16,2);
  4.  
  5. // RemoteXY select connection mode and include library
  6. #define REMOTEXY_MODE__HARDSERIAL
  7.  
  8. #include <RemoteXY.h>
  9.  
  10. // RemoteXY connection settings
  11. #define REMOTEXY_SERIAL Serial
  12. #define REMOTEXY_SERIAL_SPEED 9600
  13.  
  14.  
  15. // RemoteXY configurate
  16. #pragma pack(push, 1)
  17. uint8_t RemoteXY_CONF[] =
  18. { 255,6,0,0,0,112,0,10,120,0,
  19. 2,1,2,2,18,9,1,26,31,31,
  20. 78,121,97,108,97,104,0,77,97,116,
  21. 105,0,5,20,69,32,30,30,120,24,
  22. 31,3,130,82,2,16,9,1,26,2,
  23. 1,2,50,18,9,120,26,31,31,76,
  24. 97,109,112,117,32,110,121,97,108,97,
  25. 104,0,76,97,109,112,117,32,109,97,
  26. 116,105,0,2,1,2,36,18,9,120,
  27. 26,31,31,83,105,114,101,110,101,32,
  28. 110,121,97,108,97,104,0,83,105,114,
  29. 101,110,101,32,109,97,116,105,0 };
  30.  
  31. // this structure defines all the variables and events of your control interface
  32. struct {
  33.  
  34. // input variables
  35. uint8_t saklar; // =1 if switch ON and =0 if OFF
  36. int8_t joystick_1_x; // =-100..100 x-coordinate joystick position
  37. int8_t joystick_1_y; // =-100..100 y-coordinate joystick position
  38. uint8_t select_1; // =0 if select position A, =1 if position B, =2 if position C, ...
  39. uint8_t lampu; // =1 if switch ON and =0 if OFF
  40. uint8_t sirene; // =1 if switch ON and =0 if OFF
  41.  
  42. // other variable
  43. uint8_t connect_flag; // =1 if wire connected, else =0
  44.  
  45. } RemoteXY;
  46.  
  47. int Signal;
  48. int Threshold = 550;
  49. int count = 0;
  50. int ledState1 = LOW;
  51.  
  52. unsigned long previousMillis1 = 0;
  53. unsigned long previousMillis2 = 0;
  54. unsigned long previousMillis3 = 0;
  55.  
  56. const long interval1 = 750;
  57. const long interval2 = 3000;
  58. const long interval3 = 1000;
  59.  
  60. /* defined the right motor control pins */
  61. #define PIN_MOTOR_RIGHT_UP 7
  62. #define PIN_MOTOR_RIGHT_DN 6
  63. #define PIN_MOTOR_RIGHT_SPEED 10
  64.  
  65. /* defined the left motor control pins */
  66. #define PIN_MOTOR_LEFT_UP 5
  67. #define PIN_MOTOR_LEFT_DN 4
  68. #define PIN_MOTOR_LEFT_SPEED 9
  69.  
  70. #define PIN_SAKLAR 13
  71. #define PIN_LAMPU 11
  72. #define PIN_SIRENE 12
  73.  
  74. /* defined two arrays with a list of pins for each motor */
  75. unsigned char RightMotor[3] =
  76. {PIN_MOTOR_RIGHT_UP, PIN_MOTOR_RIGHT_DN, PIN_MOTOR_RIGHT_SPEED};
  77. unsigned char LeftMotor[3] =
  78. {PIN_MOTOR_LEFT_UP, PIN_MOTOR_LEFT_DN, PIN_MOTOR_LEFT_SPEED};
  79.  
  80. /*
  81. speed control of the motor
  82. motor - pointer to an array of pins
  83. v - motor speed can be set from -100 to 100
  84. */
  85. void Wheel (unsigned char * motor, int v)
  86. {
  87. if (v>100) v=100;
  88. if (v<-100) v=-100;
  89. if (v>0) {
  90. digitalWrite(motor[0], HIGH);
  91. digitalWrite(motor[1], LOW);
  92. analogWrite(motor[2], v*2.55);
  93. }
  94. else if (v<0) {
  95. digitalWrite(motor[0], LOW);
  96. digitalWrite(motor[1], HIGH);
  97. analogWrite(motor[2], (-v)*2.55);
  98. }
  99. else {
  100. digitalWrite(motor[0], LOW);
  101. digitalWrite(motor[1], LOW);
  102. analogWrite(motor[2], 0);
  103. }
  104. }
  105.  
  106. byte Eyes1[8] = {
  107. B11111,
  108. B10000,
  109. B10000,
  110. B10000,
  111. B10000,
  112. B10000,
  113. B10000,
  114. B11111
  115. };
  116.  
  117. byte Eyes2[8] = {
  118. B11111,
  119. B00000,
  120. B00000,
  121. B11111,
  122. B11111,
  123. B00000,
  124. B00000,
  125. B11111
  126. };
  127.  
  128. byte Eyes3[8] = {
  129. B11111,
  130. B00001,
  131. B00001,
  132. B00001,
  133. B00001,
  134. B00001,
  135. B00001,
  136. B11111
  137. };
  138.  
  139. byte Sleep1[8] = {
  140. B00000,
  141. B00000,
  142. B00000,
  143. B11111,
  144. B11111,
  145. B00000,
  146. B00000,
  147. B00000
  148. };
  149.  
  150. byte senyum1[8] = {
  151. B00000,
  152. B00000,
  153. B00001,
  154. B00011,
  155. B00110,
  156. B01100,
  157. B11000,
  158. B10000
  159. };
  160.  
  161. byte senyum2[8] = {
  162. B00000,
  163. B00000,
  164. B11111,
  165. B11111,
  166. B00000,
  167. B00000,
  168. B00000,
  169. B00000
  170. };
  171.  
  172. byte senyum3[8] = {
  173. B00000,
  174. B00000,
  175. B10000,
  176. B11000,
  177. B01100,
  178. B00110,
  179. B00011,
  180. B00001
  181. };
  182.  
  183. byte senyummouth1[8] = {
  184. B10000,
  185. B11000,
  186. B01100,
  187. B00110,
  188. B00011,
  189. B00001,
  190. B00000,
  191. B00000
  192. };
  193.  
  194. byte senyummouth2[8] = {
  195. B00000,
  196. B00000,
  197. B00000,
  198. B00000,
  199. B11111,
  200. B11111,
  201. B00000,
  202. B00000
  203. };
  204.  
  205. byte senyummouth3[8] = {
  206. B00001,
  207. B00011,
  208. B00110,
  209. B01100,
  210. B11000,
  211. B10000,
  212. B00000,
  213. B00000
  214. };
  215.  
  216. void setup() {
  217. lcd.begin();
  218. lcd.setBacklight(HIGH);
  219.  
  220. pinMode (PIN_MOTOR_RIGHT_UP, OUTPUT);
  221. pinMode (PIN_MOTOR_RIGHT_DN, OUTPUT);
  222. pinMode (PIN_MOTOR_LEFT_UP, OUTPUT);
  223. pinMode (PIN_MOTOR_LEFT_DN, OUTPUT);
  224.  
  225. pinMode (PIN_SAKLAR, OUTPUT);
  226. pinMode (PIN_LAMPU, OUTPUT);
  227. pinMode (PIN_SIRENE, OUTPUT);
  228.  
  229. /* initialization module RemoteXY */
  230. RemoteXY_Init ();
  231.  
  232. lcd.createChar(0, Eyes1);
  233. lcd.createChar(1, Eyes2);
  234. lcd.createChar(2, Eyes3);
  235. lcd.createChar(3, Sleep1);
  236. lcd.createChar(4, senyum1);
  237. lcd.createChar(5, senyum2);
  238. lcd.createChar(6, senyum3);
  239. lcd.createChar(7, senyummouth1);
  240. lcd.createChar(8, senyummouth2);
  241. lcd.createChar(9, senyummouth3);
  242.  
  243. lcd.clear();
  244. }
  245.  
  246. void loop() {
  247. unsigned long currentMillis = millis();
  248.  
  249. RemoteXY_Handler ();
  250.  
  251. if (RemoteXY.saklar!=0) {
  252.  
  253. /* manage the right motor */
  254. Wheel (RightMotor, RemoteXY.joystick_1_y - RemoteXY.joystick_1_x);
  255. /* manage the left motor */
  256. Wheel (LeftMotor, RemoteXY.joystick_1_y + RemoteXY.joystick_1_x);
  257.  
  258. lcd.setBacklight(HIGH);
  259.  
  260. digitalWrite(PIN_SAKLAR, HIGH);
  261.  
  262. if (RemoteXY.lampu!=0) {
  263. digitalWrite(PIN_LAMPU, HIGH);
  264. }
  265. else {
  266. digitalWrite(PIN_LAMPU, LOW);
  267. }
  268.  
  269. if (RemoteXY.sirene!=0) {
  270. digitalWrite(PIN_SIRENE, HIGH);
  271. }
  272. else
  273. {
  274. digitalWrite(PIN_SIRENE, LOW);
  275. }
  276.  
  277. if (RemoteXY.select_1==0) {
  278. if (currentMillis - previousMillis1 >= interval1) {
  279. previousMillis1 = currentMillis;
  280. lcd.clear();
  281. lcd.setCursor(0,0);
  282. lcd.write(byte(0));
  283. lcd.setCursor(1,0);
  284. lcd.write(byte(1));
  285. lcd.setCursor(2,0);
  286. lcd.write(byte(1));
  287. lcd.setCursor(3,0);
  288. lcd.write(byte(2));
  289.  
  290. lcd.setCursor(6,1);
  291. lcd.write(byte(3));
  292. lcd.setCursor(7,1);
  293. lcd.write(byte(3));
  294. lcd.setCursor(8,1);
  295. lcd.write(byte(3));
  296. lcd.setCursor(9,1);
  297. lcd.write(byte(3));
  298.  
  299. lcd.setCursor(12,0);
  300. lcd.write(byte(0));
  301. lcd.setCursor(13,0);
  302. lcd.write(byte(1));
  303. lcd.setCursor(14,0);
  304. lcd.write(byte(1));
  305. lcd.setCursor(15,0);
  306. lcd.write(byte(2));
  307. }
  308. else if (currentMillis - previousMillis2 >= interval2) {
  309. previousMillis2 = currentMillis;
  310. lcd.clear();
  311. lcd.setCursor(0,0);
  312. lcd.write(byte(3));
  313. lcd.setCursor(1,0);
  314. lcd.write(byte(3));
  315. lcd.setCursor(2,0);
  316. lcd.write(byte(3));
  317. lcd.setCursor(3,0);
  318. lcd.write(byte(3));
  319.  
  320. lcd.setCursor(6,1);
  321. lcd.write(byte(3));
  322. lcd.setCursor(7,1);
  323. lcd.write(byte(3));
  324. lcd.setCursor(8,1);
  325. lcd.write(byte(3));
  326. lcd.setCursor(9,1);
  327. lcd.write(byte(3));
  328.  
  329. lcd.setCursor(12,0);
  330. lcd.write(byte(3));
  331. lcd.setCursor(13,0);
  332. lcd.write(byte(3));
  333. lcd.setCursor(14,0);
  334. lcd.write(byte(3));
  335. lcd.setCursor(15,0);
  336. lcd.write(byte(3));
  337. }
  338. }
  339. else if (RemoteXY.select_1==1) {
  340. if (currentMillis - previousMillis3 >= interval3) {
  341. previousMillis3 = currentMillis;
  342. lcd.clear();
  343. lcd.setCursor(0,0);
  344. lcd.write(byte(4));
  345. lcd.setCursor(1,0);
  346. lcd.write(byte(5));
  347. lcd.setCursor(2,0);
  348. lcd.write(byte(5));
  349. lcd.setCursor(3,0);
  350. lcd.write(byte(6));
  351.  
  352. lcd.setCursor(6,1);
  353. lcd.write(byte(7));
  354. lcd.setCursor(7,1);
  355. lcd.write(byte(8));
  356. lcd.setCursor(8,1);
  357. lcd.write(byte(8));
  358. lcd.setCursor(9,1);
  359. lcd.write(byte(9));
  360.  
  361. lcd.setCursor(12,0);
  362. lcd.write(byte(4));
  363. lcd.setCursor(13,0);
  364. lcd.write(byte(5));
  365. lcd.setCursor(14,0);
  366. lcd.write(byte(5));
  367. lcd.setCursor(15,0);
  368. lcd.write(byte(6));
  369. }
  370. }
  371. }
  372. else {
  373. lcd.setBacklight(LOW);
  374. digitalWrite(PIN_SAKLAR, LOW);
  375. digitalWrite(PIN_LAMPU, LOW);
  376. digitalWrite(PIN_SIRENE, LOW);
  377. lcd.clear();
  378. }
  379. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement