Components and supplies
Arduino Mega 2560
Arduino Nano R3
Project description
Code
receiver_tank_v1.ino
arduino
1#include <Servo.h> 2Servo servoX; 3Servo servoY; 4 5byte X = 87; 6byte Xmin = 10; 7byte Xmax = 165; 8 9byte Xplus = 0; 10byte Yplus = 0; 11 12byte Y = 78; 13byte Ymin = 60; 14byte Ymax = 103; 15byte turret = 0; // (1 X+, 2 X-) 16 17byte IncomingCount = 0; // 18byte Byte2incoming[2] = {0,0}; // 19byte b_registry = 0; // 20 21byte laserPWM = 128; 22byte buttonS = 0; // 23 24byte motorS = 14; // 25byte Speed1_pwm = 56; // 26byte Speed2_pwm = 96; // 27byte Speed3_pwm = 255; // 28byte Speed1RL_pwm = 88; // 29byte Speed2RL_pwm = 112; // 30byte Speed3RL_pwm = 255; // 31byte Speed0RL_pwm = 128; // 32 33 34void setup() { 35 36Serial.begin(9600); 37// !!! 38Serial.setTimeout(500); 39 40pinMode(02, OUTPUT); // light - 41pinMode(06, OUTPUT); // laser - 42pinMode(11, OUTPUT); // gun - 43pinMode(13, OUTPUT); // 44 45// L298N 46pinMode(3, OUTPUT); //D3 - ENA 47pinMode(17, OUTPUT); //AO - INPUT1 48pinMode(16, OUTPUT); //A1 - INPUT2 49 50pinMode(15, OUTPUT); //A2 - INPUT3 51pinMode(14, OUTPUT); //A3 - INPUT4 52pinMode(5, OUTPUT); //D5 - ENB 53 54servoX.attach(9); 55servoY.attach(10); 56// 57servoX.write(X); 58servoY.write(Y); 59} 60 61void loop() { 62 63// 1.5 2- 64// 1.5 65// 66 67IncomingCount = Serial.readBytes(Byte2incoming,2); 68 69if (IncomingCount > 1) { // 2 - 70//digitalWrite(13, LOW); 71// 2- !!! 72b_registry = Byte2incoming[0]; 73// !!! 74if (b_registry == 1) buttonS = Byte2incoming[1]; 75// !!! 76if (b_registry == 2) motorS = Byte2incoming[1]; 77// !!! 78if (b_registry == 3) turret = Byte2incoming[1]; 79 80// 2 - 81Serial.write (Byte2incoming,2); 82} else { // ( ) 1.5 83//digitalWrite(13, HIGH); 84// - !!! 85} 86 87//---------------------------------------------------| 88// | 89//---------------------------------------------------| 90 91digitalWrite(02,bitRead(buttonS, 0)); // light - 92 93if (bitRead(buttonS, 1)) { // laser Sight - 94analogWrite(6, laserPWM); // 95} else analogWrite(6, 0); 96 97if (bitRead(buttonS, 2)) { // 98analogWrite(11,160); // 99delay(125); // pwm160 100analogWrite(11,0); // 125ms 101bitWrite(buttonS, 2, 0); // 102} 103 104//---------------------------------------------------| 105// L298N | 106//---------------------------------------------------| 107 108if (motorS == 14){ 109// 110analogWrite(3, 0); //D3 - ENA 111digitalWrite(14, 0); //AO - INPUT1 112digitalWrite(15, 0); //A1 - INPUT2 113// 114analogWrite(5, 0); //D5 - ENA 115digitalWrite(16, 0); //A2 - INPUT3 116digitalWrite(17, 0); //A3 - INPUT4 117} 118 119// 120 121if (motorS == 15){ 122// 123analogWrite(3, Speed1_pwm); //D3 - ENA 124digitalWrite(16, 1); //AO - INPUT1 125digitalWrite(17, 0); //A1 - INPUT2 126// 127analogWrite(5, Speed1_pwm); //D5 - ENA 128digitalWrite(14, 1); //A2 - INPUT3 129digitalWrite(15, 0); //A3 - INPUT4 130} 131 132if (motorS == 13){ 133// 134analogWrite(3, Speed1_pwm); //D3 - ENA 135digitalWrite(16, 0); //AO - INPUT1 136digitalWrite(17, 1); //A1 - INPUT2 137// 138analogWrite(5, Speed1_pwm); //D5 - ENA 139digitalWrite(14, 0); //A2 - INPUT3 140digitalWrite(15, 1); //A3 - INPUT4 141} 142 143if (motorS == 24){ 144// 145analogWrite(3, Speed1RL_pwm); //D3 - ENA 146digitalWrite(16, 0); //AO - INPUT1 147digitalWrite(17, 0); //A1 - INPUT2 148// 149analogWrite(5, Speed1RL_pwm); //D5 - ENA 150digitalWrite(14, 1); //A2 - INPUT3 151digitalWrite(15, 0); //A3 - INPUT4 152} 153 154if (motorS == 31){ 155// 156analogWrite(3, Speed1RL_pwm); //D3 - ENA 157digitalWrite(16, 1); //AO - INPUT1 158digitalWrite(17, 0); //A1 - INPUT2 159// 160analogWrite(5, Speed1RL_pwm); //D5 - ENA 161digitalWrite(14, 0); //A2 - INPUT3 162digitalWrite(15, 0); //A3 - INPUT4 163} 164 165if (motorS == 26){ 166// 167analogWrite(3, Speed1RL_pwm); //D3 - ENA 168digitalWrite(16, 0); //AO - INPUT1 169digitalWrite(17, 0); //A1 - INPUT2 170// 171analogWrite(5, Speed1RL_pwm); //D5 - ENA 172digitalWrite(14, 0); //A2 - INPUT3 173digitalWrite(15, 1); //A3 - INPUT4 174} 175 176if (motorS == 33){ 177// 178analogWrite(3, Speed1RL_pwm); //D3 - ENA 179digitalWrite(16, 0); //AO - INPUT1 180digitalWrite(17, 1); //A1 - INPUT2 181// 182analogWrite(5, Speed1RL_pwm); //D5 - ENA 183digitalWrite(14, 0); //A2 - INPUT3 184digitalWrite(15, 0); //A3 - INPUT4 185} 186 187 188// 189 190if (motorS == 17){ 191// 192analogWrite(3, Speed3_pwm); //D3 - ENA 193digitalWrite(16, 1); //AO - INPUT1 194digitalWrite(17, 0); //A1 - INPUT2 195// 196analogWrite(5, Speed3_pwm); //D5 - ENA 197digitalWrite(14, 1); //A2 - INPUT3 198digitalWrite(15, 0); //A3 - INPUT4 199} 200 201if (motorS == 11){ 202// 203analogWrite(3, Speed3_pwm); //D3 - ENA 204digitalWrite(16, 0); //AO - INPUT1 205digitalWrite(17, 1); //A1 - INPUT2 206// 207analogWrite(5, Speed3_pwm); //D5 - ENA 208digitalWrite(14, 0); //A2 - INPUT3 209digitalWrite(15, 1); //A3 - INPUT4 210} 211 212if (motorS == 22){ 213// 214analogWrite(3, Speed3RL_pwm); //D3 - ENA 215digitalWrite(16, 0); //AO - INPUT1 216digitalWrite(17, 0); //A1 - INPUT2 217// 218analogWrite(5, Speed3RL_pwm); //D5 - ENA 219digitalWrite(14, 1); //A2 - INPUT3 220digitalWrite(15, 0); //A3 - INPUT4 221} 222 223if (motorS == 29){ 224// 225analogWrite(3, Speed3RL_pwm); //D3 - ENA 226digitalWrite(16, 1); //AO - INPUT1 227digitalWrite(17, 0); //A1 - INPUT2 228// 229analogWrite(5, Speed3RL_pwm); //D5 - ENA 230digitalWrite(14, 0); //A2 - INPUT3 231digitalWrite(15, 0); //A3 - INPUT4 232} 233 234if (motorS == 28){ 235// 236analogWrite(3, Speed3RL_pwm); //D3 - ENA 237digitalWrite(16, 0); //AO - INPUT1 238digitalWrite(17, 0); //A1 - INPUT2 239// 240analogWrite(5, Speed3RL_pwm); //D5 - ENA 241digitalWrite(14, 0); //A2 - INPUT3 242digitalWrite(15, 1); //A3 - INPUT4 243} 244 245if (motorS == 35){ 246// 247analogWrite(3, Speed3RL_pwm); //D3 - ENA 248digitalWrite(16, 0); //AO - INPUT1 249digitalWrite(17, 1); //A1 - INPUT2 250// 251analogWrite(5, Speed3RL_pwm); //D5 - ENA 252digitalWrite(14, 0); //A2 - INPUT3 253digitalWrite(15, 0); //A3 - INPUT4 254} 255 256// 4 257 258 259 260//4 261 262if (motorS == 16){ 263// 264analogWrite(3, Speed2_pwm); //D3 - ENA 265digitalWrite(16, 1); //AO - INPUT1 266digitalWrite(17, 0); //A1 - INPUT2 267// 268analogWrite(5, Speed2_pwm); //D5 - ENA 269digitalWrite(14, 1); //A2 - INPUT3 270digitalWrite(15, 0); //A3 - INPUT4 271} 272 273if (motorS == 12){ 274// 275analogWrite(3, Speed2_pwm); //D3 - ENA 276digitalWrite(16, 0); //AO - INPUT1 277digitalWrite(17, 1); //A1 - INPUT2 278// 279analogWrite(5, Speed2_pwm); //D5 - ENA 280digitalWrite(14, 0); //A2 - INPUT3 281digitalWrite(15, 1); //A3 - INPUT4 282} 283 284if (motorS == 23){ 285// 286analogWrite(3, Speed2RL_pwm); //D3 - ENA 287digitalWrite(16, 0); //AO - INPUT1 288digitalWrite(17, 0); //A1 - INPUT2 289// 290analogWrite(5, Speed2RL_pwm); //D5 - ENA 291digitalWrite(14, 1); //A2 - INPUT3 292digitalWrite(15, 0); //A3 - INPUT4 293} 294 295if (motorS == 30){ 296// 297analogWrite(3, Speed2RL_pwm); //D3 - ENA 298digitalWrite(16, 1); //AO - INPUT1 299digitalWrite(17, 0); //A1 - INPUT2 300// 301analogWrite(5, Speed2RL_pwm); //D5 - ENA 302digitalWrite(14, 0); //A2 - INPUT3 303digitalWrite(15, 0); //A3 - INPUT4 304} 305 306if (motorS == 27){ 307// 308analogWrite(3, Speed2RL_pwm); //D3 - ENA 309digitalWrite(16, 0); //AO - INPUT1 310digitalWrite(17, 0); //A1 - INPUT2 311// 312analogWrite(5, Speed2RL_pwm); //D5 - ENA 313digitalWrite(14, 0); //A2 - INPUT3 314digitalWrite(15, 1); //A3 - INPUT4 315} 316 317if (motorS == 34){ 318// 319analogWrite(3, Speed2RL_pwm); //D3 - ENA 320digitalWrite(16, 0); //AO - INPUT1 321digitalWrite(17, 1); //A1 - INPUT2 322// 323analogWrite(5, Speed2RL_pwm); //D5 - ENA 324digitalWrite(14, 0); //A2 - INPUT3 325digitalWrite(15, 0); //A3 - INPUT4 326} 327 328// 4 329 330// 331 332if (motorS == 32){ 333// 334analogWrite(3, Speed0RL_pwm); //D3 - ENA 335digitalWrite(16, 1); //AO - INPUT1 336digitalWrite(17, 0); //A1 - INPUT2 337// 338analogWrite(5, Speed0RL_pwm); //D5 - ENA 339digitalWrite(14, 0); //A2 - INPUT3 340digitalWrite(15, 1); //A3 - INPUT4 341} 342 343if (motorS == 25){ 344// 345analogWrite(3, Speed0RL_pwm); //D3 - ENA 346digitalWrite(16, 0); //AO - INPUT1 347digitalWrite(17, 1); //A1 - INPUT2 348// 349analogWrite(5, Speed0RL_pwm); //D5 - ENA 350digitalWrite(14, 1); //A2 - INPUT3 351digitalWrite(15, 0); //A3 - INPUT4 352} 353 354// 355 356if (bitRead(turret,4)) Xplus = Xplus + 1; else Xplus = 0; 357 358if (bitRead(turret,1) && ((X<Xmax))) X=X+1+Xplus; 359if (bitRead(turret,0) && ((X>Xmin))) X=X-1-Xplus; 360 361servoX.write(X); 362 363if (bitRead(turret,3) && ((Y<Ymax))) Y=Y+1; 364if (bitRead(turret,2) && ((Y>Ymin))) Y=Y-1; 365 366servoY.write(Y); 367 368} 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
receiver_tank_v1.ino
arduino
1#include <Servo.h> 2Servo servoX; 3Servo servoY; 4 5byte X = 87; 6byte Xmin = 10; 7byte Xmax = 165; 8 9byte Xplus = 0; 10byte Yplus = 0; 11 12byte Y = 78; 13byte Ymin = 60; 14byte Ymax = 103; 15byte turret = 0; // (1 X+, 2 X-) 16 17byte IncomingCount = 0; // 18byte Byte2incoming[2] = {0,0}; // 19byte b_registry = 0; // 20 21byte laserPWM = 128; 22byte buttonS = 0; // 23 24byte motorS = 14; // 25byte Speed1_pwm = 56; // 26byte Speed2_pwm = 96; // 27byte Speed3_pwm = 255; // 28byte Speed1RL_pwm = 88; // 29byte Speed2RL_pwm = 112; // 30byte Speed3RL_pwm = 255; // 31byte Speed0RL_pwm = 128; // 32 33 34void setup() { 35 36Serial.begin(9600); 37// !!! 38Serial.setTimeout(500); 39 40pinMode(02, OUTPUT); // light - 41pinMode(06, OUTPUT); // laser - 42pinMode(11, OUTPUT); // gun - 43pinMode(13, OUTPUT); // 44 45// L298N 46pinMode(3, OUTPUT); //D3 - ENA 47pinMode(17, OUTPUT); //AO - INPUT1 48pinMode(16, OUTPUT); //A1 - INPUT2 49 50pinMode(15, OUTPUT); //A2 - INPUT3 51pinMode(14, OUTPUT); //A3 - INPUT4 52pinMode(5, OUTPUT); //D5 - ENB 53 54servoX.attach(9); 55servoY.attach(10); 56// 57servoX.write(X); 58servoY.write(Y); 59} 60 61void loop() { 62 63// 1.5 2- 64// 1.5 65// 66 67IncomingCount = Serial.readBytes(Byte2incoming,2); 68 69if (IncomingCount > 1) { // 2 - 70//digitalWrite(13, LOW); 71// 2- !!! 72b_registry = Byte2incoming[0]; 73// !!! 74if (b_registry == 1) buttonS = Byte2incoming[1]; 75// !!! 76if (b_registry == 2) motorS = Byte2incoming[1]; 77// !!! 78if (b_registry == 3) turret = Byte2incoming[1]; 79 80// 2 - 81Serial.write (Byte2incoming,2); 82} else { // ( ) 1.5 83//digitalWrite(13, HIGH); 84// - !!! 85} 86 87//---------------------------------------------------| 88// | 89//---------------------------------------------------| 90 91digitalWrite(02,bitRead(buttonS, 0)); // light - 92 93if (bitRead(buttonS, 1)) { // laser Sight - 94analogWrite(6, laserPWM); // 95} else analogWrite(6, 0); 96 97if (bitRead(buttonS, 2)) { // 98analogWrite(11,160); // 99delay(125); // pwm160 100analogWrite(11,0); // 125ms 101bitWrite(buttonS, 2, 0); // 102} 103 104//---------------------------------------------------| 105// L298N | 106//---------------------------------------------------| 107 108if (motorS == 14){ 109// 110analogWrite(3, 0); //D3 - ENA 111digitalWrite(14, 0); //AO - INPUT1 112digitalWrite(15, 0); //A1 - INPUT2 113// 114analogWrite(5, 0); //D5 - ENA 115digitalWrite(16, 0); //A2 - INPUT3 116digitalWrite(17, 0); //A3 - INPUT4 117} 118 119// 120 121if (motorS == 15){ 122// 123analogWrite(3, Speed1_pwm); //D3 - ENA 124digitalWrite(16, 1); //AO - INPUT1 125digitalWrite(17, 0); //A1 - INPUT2 126// 127analogWrite(5, Speed1_pwm); //D5 - ENA 128digitalWrite(14, 1); //A2 - INPUT3 129digitalWrite(15, 0); //A3 - INPUT4 130} 131 132if (motorS == 13){ 133// 134analogWrite(3, Speed1_pwm); //D3 - ENA 135digitalWrite(16, 0); //AO - INPUT1 136digitalWrite(17, 1); //A1 - INPUT2 137// 138analogWrite(5, Speed1_pwm); //D5 - ENA 139digitalWrite(14, 0); //A2 - INPUT3 140digitalWrite(15, 1); //A3 - INPUT4 141} 142 143if (motorS == 24){ 144// 145analogWrite(3, Speed1RL_pwm); //D3 - ENA 146digitalWrite(16, 0); //AO - INPUT1 147digitalWrite(17, 0); //A1 - INPUT2 148// 149analogWrite(5, Speed1RL_pwm); //D5 - ENA 150digitalWrite(14, 1); //A2 - INPUT3 151digitalWrite(15, 0); //A3 - INPUT4 152} 153 154if (motorS == 31){ 155// 156analogWrite(3, Speed1RL_pwm); //D3 - ENA 157digitalWrite(16, 1); //AO - INPUT1 158digitalWrite(17, 0); //A1 - INPUT2 159// 160analogWrite(5, Speed1RL_pwm); //D5 - ENA 161digitalWrite(14, 0); //A2 - INPUT3 162digitalWrite(15, 0); //A3 - INPUT4 163} 164 165if (motorS == 26){ 166// 167analogWrite(3, Speed1RL_pwm); //D3 - ENA 168digitalWrite(16, 0); //AO - INPUT1 169digitalWrite(17, 0); //A1 - INPUT2 170// 171analogWrite(5, Speed1RL_pwm); //D5 - ENA 172digitalWrite(14, 0); //A2 - INPUT3 173digitalWrite(15, 1); //A3 - INPUT4 174} 175 176if (motorS == 33){ 177// 178analogWrite(3, Speed1RL_pwm); //D3 - ENA 179digitalWrite(16, 0); //AO - INPUT1 180digitalWrite(17, 1); //A1 - INPUT2 181// 182analogWrite(5, Speed1RL_pwm); //D5 - ENA 183digitalWrite(14, 0); //A2 - INPUT3 184digitalWrite(15, 0); //A3 - INPUT4 185} 186 187 188// 189 190if (motorS == 17){ 191// 192analogWrite(3, Speed3_pwm); //D3 - ENA 193digitalWrite(16, 1); //AO - INPUT1 194digitalWrite(17, 0); //A1 - INPUT2 195// 196analogWrite(5, Speed3_pwm); //D5 - ENA 197digitalWrite(14, 1); //A2 - INPUT3 198digitalWrite(15, 0); //A3 - INPUT4 199} 200 201if (motorS == 11){ 202// 203analogWrite(3, Speed3_pwm); //D3 - ENA 204digitalWrite(16, 0); //AO - INPUT1 205digitalWrite(17, 1); //A1 - INPUT2 206// 207analogWrite(5, Speed3_pwm); //D5 - ENA 208digitalWrite(14, 0); //A2 - INPUT3 209digitalWrite(15, 1); //A3 - INPUT4 210} 211 212if (motorS == 22){ 213// 214analogWrite(3, Speed3RL_pwm); //D3 - ENA 215digitalWrite(16, 0); //AO - INPUT1 216digitalWrite(17, 0); //A1 - INPUT2 217// 218analogWrite(5, Speed3RL_pwm); //D5 - ENA 219digitalWrite(14, 1); //A2 - INPUT3 220digitalWrite(15, 0); //A3 - INPUT4 221} 222 223if (motorS == 29){ 224// 225analogWrite(3, Speed3RL_pwm); //D3 - ENA 226digitalWrite(16, 1); //AO - INPUT1 227digitalWrite(17, 0); //A1 - INPUT2 228// 229analogWrite(5, Speed3RL_pwm); //D5 - ENA 230digitalWrite(14, 0); //A2 - INPUT3 231digitalWrite(15, 0); //A3 - INPUT4 232} 233 234if (motorS == 28){ 235// 236analogWrite(3, Speed3RL_pwm); //D3 - ENA 237digitalWrite(16, 0); //AO - INPUT1 238digitalWrite(17, 0); //A1 - INPUT2 239// 240analogWrite(5, Speed3RL_pwm); //D5 - ENA 241digitalWrite(14, 0); //A2 - INPUT3 242digitalWrite(15, 1); //A3 - INPUT4 243} 244 245if (motorS == 35){ 246// 247analogWrite(3, Speed3RL_pwm); //D3 - ENA 248digitalWrite(16, 0); //AO - INPUT1 249digitalWrite(17, 1); //A1 - INPUT2 250// 251analogWrite(5, Speed3RL_pwm); //D5 - ENA 252digitalWrite(14, 0); //A2 - INPUT3 253digitalWrite(15, 0); //A3 - INPUT4 254} 255 256// 4 257 258 259 260//4 261 262if (motorS == 16){ 263// 264analogWrite(3, Speed2_pwm); //D3 - ENA 265digitalWrite(16, 1); //AO - INPUT1 266digitalWrite(17, 0); //A1 - INPUT2 267// 268analogWrite(5, Speed2_pwm); //D5 - ENA 269digitalWrite(14, 1); //A2 - INPUT3 270digitalWrite(15, 0); //A3 - INPUT4 271} 272 273if (motorS == 12){ 274// 275analogWrite(3, Speed2_pwm); //D3 - ENA 276digitalWrite(16, 0); //AO - INPUT1 277digitalWrite(17, 1); //A1 - INPUT2 278// 279analogWrite(5, Speed2_pwm); //D5 - ENA 280digitalWrite(14, 0); //A2 - INPUT3 281digitalWrite(15, 1); //A3 - INPUT4 282} 283 284if (motorS == 23){ 285// 286analogWrite(3, Speed2RL_pwm); //D3 - ENA 287digitalWrite(16, 0); //AO - INPUT1 288digitalWrite(17, 0); //A1 - INPUT2 289// 290analogWrite(5, Speed2RL_pwm); //D5 - ENA 291digitalWrite(14, 1); //A2 - INPUT3 292digitalWrite(15, 0); //A3 - INPUT4 293} 294 295if (motorS == 30){ 296// 297analogWrite(3, Speed2RL_pwm); //D3 - ENA 298digitalWrite(16, 1); //AO - INPUT1 299digitalWrite(17, 0); //A1 - INPUT2 300// 301analogWrite(5, Speed2RL_pwm); //D5 - ENA 302digitalWrite(14, 0); //A2 - INPUT3 303digitalWrite(15, 0); //A3 - INPUT4 304} 305 306if (motorS == 27){ 307// 308analogWrite(3, Speed2RL_pwm); //D3 - ENA 309digitalWrite(16, 0); //AO - INPUT1 310digitalWrite(17, 0); //A1 - INPUT2 311// 312analogWrite(5, Speed2RL_pwm); //D5 - ENA 313digitalWrite(14, 0); //A2 - INPUT3 314digitalWrite(15, 1); //A3 - INPUT4 315} 316 317if (motorS == 34){ 318// 319analogWrite(3, Speed2RL_pwm); //D3 - ENA 320digitalWrite(16, 0); //AO - INPUT1 321digitalWrite(17, 1); //A1 - INPUT2 322// 323analogWrite(5, Speed2RL_pwm); //D5 - ENA 324digitalWrite(14, 0); //A2 - INPUT3 325digitalWrite(15, 0); //A3 - INPUT4 326} 327 328// 4 329 330// 331 332if (motorS == 32){ 333// 334analogWrite(3, Speed0RL_pwm); //D3 - ENA 335digitalWrite(16, 1); //AO - INPUT1 336digitalWrite(17, 0); //A1 - INPUT2 337// 338analogWrite(5, Speed0RL_pwm); //D5 - ENA 339digitalWrite(14, 0); //A2 - INPUT3 340digitalWrite(15, 1); //A3 - INPUT4 341} 342 343if (motorS == 25){ 344// 345analogWrite(3, Speed0RL_pwm); //D3 - ENA 346digitalWrite(16, 0); //AO - INPUT1 347digitalWrite(17, 1); //A1 - INPUT2 348// 349analogWrite(5, Speed0RL_pwm); //D5 - ENA 350digitalWrite(14, 1); //A2 - INPUT3 351digitalWrite(15, 0); //A3 - INPUT4 352} 353 354// 355 356if (bitRead(turret,4)) Xplus = Xplus + 1; else Xplus = 0; 357 358if (bitRead(turret,1) && ((X<Xmax))) X=X+1+Xplus; 359if (bitRead(turret,0) && ((X>Xmin))) X=X-1-Xplus; 360 361servoX.write(X); 362 363if (bitRead(turret,3) && ((Y<Ymax))) Y=Y+1; 364if (bitRead(turret,2) && ((Y>Ymin))) Y=Y-1; 365 366servoY.write(Y); 367 368} 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
transmitter_tank_v1.ino
arduino
1#include <LiquidCrystal.h> 2LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 3 4byte buttonS = 0; // 5byte buttonS_OLD = 0; // int connect = 0; 6int connect_OK = 0; // ? 7 8byte go_Old = 14; // 9byte go_New = 14; // 10byte adj_Old = 20; // 11byte adj_New = 20; // 12byte motor_Send = 14; // 13byte bounce_b = 50; // 14 15const int pinZ = 57; // 16const int pinX = A1; // X 17const int pinY = A2; // Y 18int jvalueX; // X 19int jvalueY; // Y 20byte turret = 0; // (1 X+, 2 X-) 21boolean turret_stop = false; // (1 X+, 2 X-) 22 23void setup() { 24 25Serial1.begin(9600); //open port APC220 26 27pinMode(57, INPUT); 28 29pinMode(36, INPUT_PULLUP); // light - 30pinMode(37, INPUT_PULLUP); // laser Sight - 31pinMode(38, INPUT_PULLUP); // gun - 32 33pinMode(22 , INPUT_PULLUP); 34pinMode(23 , INPUT_PULLUP); 35pinMode(24 , INPUT_PULLUP); 36pinMode(25 , INPUT_PULLUP); 37pinMode(26 , INPUT_PULLUP); 38pinMode(27 , INPUT_PULLUP); 39pinMode(28 , INPUT_PULLUP); 40 41pinMode(29 , INPUT_PULLUP); 42pinMode(30 , INPUT_PULLUP); 43pinMode(31 , INPUT_PULLUP); 44pinMode(32 , INPUT_PULLUP); 45pinMode(33 , INPUT_PULLUP); 46pinMode(34 , INPUT_PULLUP); 47pinMode(35 , INPUT_PULLUP); 48 49 50// 51lcd.begin(20, 4); 52lcd.setCursor(8, 0); 53lcd.print("LSG"); 54lcd.setCursor(8, 1); 55lcd.print("000"); 56lcd.setCursor(8, 2); 57lcd.print("---"); 58lcd.setCursor(0, 4); 59lcd.print("link--"); 60 61// 62lcd.setCursor(0, 0); 63lcd.print(go_New); 64lcd.setCursor(0, 1); 65lcd.print(adj_New); 66 67// 68 69lcd.setCursor(15, 1); 70lcd.print("j"); 71 72 73} 74 75//---------------------------------------------------| 76// 2- | 77//---------------------------------------------------| 78int Byte2sendFunction(byte BYTE1, byte BYTE2){ 79 int result; 80// !!! 81 Serial1.setTimeout(2000); 82// 2 2- 83 byte Byte2send[2] = {0,0}; // 84 byte Byte2receipt[2] = {0,0}; // 85// 86 Byte2send[0] = BYTE1; 87 Byte2send[1] = BYTE2; 88// 89 Serial1.write (Byte2send,2); 90// 91 Serial1.readBytes(Byte2receipt,2); 92// 93 if ((Byte2send[0] == Byte2receipt[0])&&(Byte2send[1] == Byte2receipt[1])) { 94// result = 1 0 95 result = 1; 96 lcd.setCursor(5, 4); 97 lcd.print("Y"); // !!! 98 } else { 99 result = 0; 100 lcd.setCursor(5, 4); 101 lcd.print("N"); // !!! 102 } 103// 104 return result; 105} 106//---------------------------------------------------| 107 108void loop() { 109 110//---------------------------------------------------| 111// !!! | 112//---------------------------------------------------| 113 114if (!digitalRead(36)) { // 115bitWrite(buttonS, 0, !(bitRead(buttonS, 0))); // 116lcd.setCursor(8, 1); 117lcd.print(bitRead(buttonS, 0)); 118} 119 120if (!digitalRead(37)) { // 121bitWrite(buttonS, 1, !(bitRead(buttonS, 1))); // 122lcd.setCursor(9, 1); 123lcd.print(bitRead(buttonS, 1)); 124} 125 126// 127bitWrite(buttonS, 2, !digitalRead(38)); // 128lcd.setCursor(10, 1); 129lcd.print(bitRead(buttonS, 2)); 130 131//---------------------------------------------------| 132// | 133//---------------------------------------------------| 134if (buttonS!=buttonS_OLD) { 135connect_OK = Byte2sendFunction(1,buttonS); 136buttonS_OLD = buttonS; 137// !!! 138if (connect_OK == 1) { 139lcd.setCursor(8, 2); 140lcd.print(bitRead(buttonS, 0)); 141lcd.setCursor(9, 2); 142lcd.print(bitRead(buttonS, 1)); 143lcd.setCursor(10,2); 144lcd.print(bitRead(buttonS, 2)); 145} 146// !!! 147if (connect_OK == 0) { 148lcd.setCursor(8, 2); 149lcd.print("---"); 150} 151} 152 153//---------------------------------------------------| 154// !!! | 155//---------------------------------------------------| 156adj_New = 20; 157 158if (!digitalRead(32)) { 159delay(bounce_b); 160if (!digitalRead(25)) go_New = 14; else adj_New = 32; 161} 162 163if (!digitalRead(25)) { 164delay(bounce_b); 165if (!digitalRead(32)) go_New = 14; else adj_New = 25; 166} 167 168if (!digitalRead(31)) { 169delay(bounce_b); 170if (!digitalRead(24)) go_New = 15; else adj_New = 31; 171} 172 173if (!digitalRead(24)) { 174delay(bounce_b); 175if (!digitalRead(31)) go_New = 15; else adj_New = 24; 176} 177 178if (!digitalRead(30)) { 179delay(bounce_b); 180if (!digitalRead(23)) go_New = 16; else adj_New = 30; 181} 182 183if (!digitalRead(23)) { 184delay(bounce_b); 185if (!digitalRead(30)) go_New = 16; else adj_New = 23; 186} 187 188if (!digitalRead(29)) { 189delay(bounce_b); 190if (!digitalRead(22)) go_New = 17; else adj_New = 29; 191} 192 193if (!digitalRead(22)) { 194delay(bounce_b); 195if (!digitalRead(29)) go_New = 17; else adj_New = 22; 196} 197 198if (!digitalRead(33)) { 199delay(bounce_b); 200if (!digitalRead(26)) go_New = 13; else adj_New = 33; 201} 202 203if (!digitalRead(26)) { 204delay(bounce_b); 205if (!digitalRead(33)) go_New = 13; else adj_New = 26; 206} 207 208if (!digitalRead(34)) { 209delay(bounce_b); 210if (!digitalRead(27)) go_New = 12; else adj_New = 34; 211} 212 213if (!digitalRead(27)) { 214delay(bounce_b); 215if (!digitalRead(34)) go_New = 12; else adj_New = 27; 216} 217 218if (!digitalRead(35)) { 219delay(bounce_b); 220if (!digitalRead(28)) go_New = 11; else adj_New = 35; 221} 222 223if (!digitalRead(28)) { 224delay(bounce_b); 225if (!digitalRead(35)) go_New = 11; else adj_New = 28; 226} 227 228if ((go_Old != go_New) || (adj_Old != adj_New)){ 229// 230lcd.setCursor(0, 0); 231lcd.print(go_New); 232lcd.setCursor(0, 1); 233lcd.print(adj_New); 234 235if (adj_New > 20) { // 236motor_Send = adj_New; 237adj_Old = adj_New; 238} else { // 239motor_Send = go_New; 240go_Old = go_New; 241adj_Old = 20; // 242} 243// !!! 244 245connect_OK = Byte2sendFunction(2,motor_Send); 246 247// !!! 248if (connect_OK == 1) { 249lcd.setCursor(0, 2); 250lcd.print(motor_Send); 251} 252// !!! 253if (connect_OK == 0) { 254lcd.setCursor(0, 2); 255lcd.print("--"); 256} 257 258} // 259 260 261//---------------------------------------------------| 262// !!! | 263//---------------------------------------------------| 264 265// !!! 266if (digitalRead(pinZ)) { 267lcd.setCursor(16, 0); 268lcd.print("Z"); 269} else { 270lcd.setCursor(16, 0); 271lcd.print("z"); 272} 273 274// 275jvalueX = analogRead(pinX); 276jvalueY = analogRead(pinY); 277turret = 0; 278//0- - 279//1- - 280if (jvalueX > 712) bitWrite(turret, 0, 1); 281if (jvalueX < 312) bitWrite(turret, 1, 1); 282//4 " " 283if ((jvalueX > 1013)||(jvalueX < 10)) bitWrite(turret, 4, 1); 284 285// 286lcd.setCursor(16, 1); 287lcd.print(bitRead(turret,0)); 288lcd.setCursor(14, 1); 289lcd.print(bitRead(turret,1)); 290 291//2- - 292//3- - 293if (jvalueY > 712) bitWrite(turret, 2, 1); 294if (jvalueY < 312) bitWrite(turret, 3, 1); 295// Y 296lcd.setCursor(15, 0); 297lcd.print(bitRead(turret,2)); 298lcd.setCursor(15, 1); 299lcd.print(bitRead(turret,3)); 300 301lcd.setCursor(15, 2); 302lcd.print(" "); 303lcd.setCursor(15, 2); 304lcd.print(jvalueX); 305 306if (turret !=0) { 307connect_OK = Byte2sendFunction(3,turret); 308turret_stop = true; 309} 310 311if ((turret == 0) && (turret_stop)) { 312connect_OK = Byte2sendFunction(3,0); 313turret_stop = false; 314} 315 316} 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
transmitter_tank_v1.ino
arduino
1#include <LiquidCrystal.h> 2LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 3 4byte 5 buttonS = 0; // 6byte buttonS_OLD = 0; // int connect = 7 0; 8int connect_OK = 0; // ? 9 10byte go_Old = 14; // 11 12byte go_New = 14; // 13byte adj_Old = 20; // 14byte 15 adj_New = 20; // 16byte motor_Send = 14; // 17byte bounce_b 18 = 50; // 19 20const int pinZ = 57; // 21const int pinX 22 = A1; // X 23const int pinY = A2; // Y 24int jvalueX; // 25 X 26int jvalueY; // Y 27byte turret = 0; // 28 (1 X+, 2 X-) 29boolean turret_stop = false; // (1 X+, 2 X-) 30 31void 32 setup() { 33 34Serial1.begin(9600); //open port APC220 35 36pinMode(57, 37 INPUT); 38 39pinMode(36, INPUT_PULLUP); // light - 40pinMode(37, INPUT_PULLUP); 41 // laser Sight - 42pinMode(38, INPUT_PULLUP); // gun - 43 44pinMode(22 45 , INPUT_PULLUP); 46pinMode(23 , INPUT_PULLUP); 47pinMode(24 , INPUT_PULLUP); 48pinMode(25 49 , INPUT_PULLUP); 50pinMode(26 , INPUT_PULLUP); 51pinMode(27 , INPUT_PULLUP); 52pinMode(28 53 , INPUT_PULLUP); 54 55pinMode(29 , INPUT_PULLUP); 56pinMode(30 , INPUT_PULLUP); 57pinMode(31 58 , INPUT_PULLUP); 59pinMode(32 , INPUT_PULLUP); 60pinMode(33 , INPUT_PULLUP); 61pinMode(34 62 , INPUT_PULLUP); 63pinMode(35 , INPUT_PULLUP); 64 65 66// 67lcd.begin(20, 68 4); 69lcd.setCursor(8, 0); 70lcd.print("LSG"); 71lcd.setCursor(8, 1); 72lcd.print("000"); 73lcd.setCursor(8, 74 2); 75lcd.print("---"); 76lcd.setCursor(0, 4); 77lcd.print("link--"); 78 79// 80 81lcd.setCursor(0, 0); 82lcd.print(go_New); 83lcd.setCursor(0, 1); 84lcd.print(adj_New); 85 86// 87 88 89lcd.setCursor(15, 1); 90lcd.print("j"); 91 92 93} 94 95//---------------------------------------------------| 96// 97 2- | 98//---------------------------------------------------| 99int Byte2sendFunction(byte 100 BYTE1, byte BYTE2){ 101 int result; 102// !!! 103 Serial1.setTimeout(2000); 104// 105 2 2- 106 byte Byte2send[2] = {0,0}; // 107 byte Byte2receipt[2] = {0,0}; 108 // 109// 110 Byte2send[0] = BYTE1; 111 Byte2send[1] = BYTE2; 112// 113 114 Serial1.write (Byte2send,2); 115// 116 Serial1.readBytes(Byte2receipt,2); 117// 118 119 if ((Byte2send[0] == Byte2receipt[0])&&(Byte2send[1] == Byte2receipt[1])) 120 { 121// result = 1 0 122 result = 1; 123 lcd.setCursor(5, 4); 124 lcd.print("Y"); 125 // !!! 126 } else { 127 result = 0; 128 lcd.setCursor(5, 4); 129 lcd.print("N"); 130 // !!! 131 } 132// 133 return result; 134} 135//---------------------------------------------------| 136 137void 138 loop() { 139 140//---------------------------------------------------| 141// !!! 142 | 143//---------------------------------------------------| 144 145if 146 (!digitalRead(36)) { // 147bitWrite(buttonS, 0, !(bitRead(buttonS, 0))); // 148 149lcd.setCursor(8, 1); 150lcd.print(bitRead(buttonS, 0)); 151} 152 153if (!digitalRead(37)) 154 { // 155bitWrite(buttonS, 1, !(bitRead(buttonS, 1))); // 156lcd.setCursor(9, 157 1); 158lcd.print(bitRead(buttonS, 1)); 159} 160 161// 162bitWrite(buttonS, 2, !digitalRead(38)); 163 // 164lcd.setCursor(10, 1); 165lcd.print(bitRead(buttonS, 2)); 166 167//---------------------------------------------------| 168// 169 | 170//---------------------------------------------------| 171if (buttonS!=buttonS_OLD) 172 { 173connect_OK = Byte2sendFunction(1,buttonS); 174buttonS_OLD = buttonS; 175// 176 !!! 177if (connect_OK == 1) { 178lcd.setCursor(8, 2); 179lcd.print(bitRead(buttonS, 180 0)); 181lcd.setCursor(9, 2); 182lcd.print(bitRead(buttonS, 1)); 183lcd.setCursor(10,2); 184lcd.print(bitRead(buttonS, 185 2)); 186} 187// !!! 188if (connect_OK == 0) { 189lcd.setCursor(8, 2); 190lcd.print("---"); 191 192} 193} 194 195//---------------------------------------------------| 196// 197 !!! | 198//---------------------------------------------------| 199adj_New 200 = 20; 201 202if (!digitalRead(32)) { 203delay(bounce_b); 204if (!digitalRead(25)) 205 go_New = 14; else adj_New = 32; 206} 207 208if (!digitalRead(25)) { 209delay(bounce_b); 210if 211 (!digitalRead(32)) go_New = 14; else adj_New = 25; 212} 213 214if (!digitalRead(31)) 215 { 216delay(bounce_b); 217if (!digitalRead(24)) go_New = 15; else adj_New = 31; 218} 219 220if 221 (!digitalRead(24)) { 222delay(bounce_b); 223if (!digitalRead(31)) go_New = 15; else 224 adj_New = 24; 225} 226 227if (!digitalRead(30)) { 228delay(bounce_b); 229if (!digitalRead(23)) 230 go_New = 16; else adj_New = 30; 231} 232 233if (!digitalRead(23)) { 234delay(bounce_b); 235if 236 (!digitalRead(30)) go_New = 16; else adj_New = 23; 237} 238 239if (!digitalRead(29)) 240 { 241delay(bounce_b); 242if (!digitalRead(22)) go_New = 17; else adj_New = 29; 243} 244 245if 246 (!digitalRead(22)) { 247delay(bounce_b); 248if (!digitalRead(29)) go_New = 17; else 249 adj_New = 22; 250} 251 252if (!digitalRead(33)) { 253delay(bounce_b); 254if (!digitalRead(26)) 255 go_New = 13; else adj_New = 33; 256} 257 258if (!digitalRead(26)) { 259delay(bounce_b); 260if 261 (!digitalRead(33)) go_New = 13; else adj_New = 26; 262} 263 264if (!digitalRead(34)) 265 { 266delay(bounce_b); 267if (!digitalRead(27)) go_New = 12; else adj_New = 34; 268} 269 270if 271 (!digitalRead(27)) { 272delay(bounce_b); 273if (!digitalRead(34)) go_New = 12; else 274 adj_New = 27; 275} 276 277if (!digitalRead(35)) { 278delay(bounce_b); 279if (!digitalRead(28)) 280 go_New = 11; else adj_New = 35; 281} 282 283if (!digitalRead(28)) { 284delay(bounce_b); 285if 286 (!digitalRead(35)) go_New = 11; else adj_New = 28; 287} 288 289if ((go_Old != 290 go_New) || (adj_Old != adj_New)){ 291// 292lcd.setCursor(0, 0); 293lcd.print(go_New); 294lcd.setCursor(0, 295 1); 296lcd.print(adj_New); 297 298if (adj_New > 20) { // 299motor_Send = 300 adj_New; 301adj_Old = adj_New; 302} else { // 303motor_Send = go_New; 304 305go_Old = go_New; 306adj_Old = 20; // 307} 308// !!! 309 310connect_OK 311 = Byte2sendFunction(2,motor_Send); 312 313// !!! 314if (connect_OK == 1) { 315lcd.setCursor(0, 316 2); 317lcd.print(motor_Send); 318} 319// !!! 320if (connect_OK == 0) { 321lcd.setCursor(0, 322 2); 323lcd.print("--"); 324} 325 326} // 327 328 329//---------------------------------------------------| 330// 331 !!! | 332//---------------------------------------------------| 333 334// 335 !!! 336if (digitalRead(pinZ)) { 337lcd.setCursor(16, 0); 338lcd.print("Z"); 339 340} else { 341lcd.setCursor(16, 0); 342lcd.print("z"); 343} 344 345// 346 347jvalueX = analogRead(pinX); 348jvalueY = analogRead(pinY); 349turret = 0; 350//0- 351 - 352//1- - 353if (jvalueX > 712) bitWrite(turret, 0, 1); 354if (jvalueX 355 < 312) bitWrite(turret, 1, 1); 356//4 " " 357if ((jvalueX > 1013)||(jvalueX 358 < 10)) bitWrite(turret, 4, 1); 359 360// 361lcd.setCursor(16, 1); 362lcd.print(bitRead(turret,0)); 363lcd.setCursor(14, 364 1); 365lcd.print(bitRead(turret,1)); 366 367//2- - 368//3- - 369if (jvalueY 370 > 712) bitWrite(turret, 2, 1); 371if (jvalueY < 312) bitWrite(turret, 3, 1); 372// 373 Y 374lcd.setCursor(15, 0); 375lcd.print(bitRead(turret,2)); 376lcd.setCursor(15, 377 1); 378lcd.print(bitRead(turret,3)); 379 380lcd.setCursor(15, 2); 381lcd.print(" 382 "); 383lcd.setCursor(15, 2); 384lcd.print(jvalueX); 385 386if (turret !=0) 387 { 388connect_OK = Byte2sendFunction(3,turret); 389turret_stop = true; 390} 391 392if 393 ((turret == 0) && (turret_stop)) { 394connect_OK 395 = Byte2sendFunction(3,0); 396turret_stop = false; 397} 398 399} 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
Downloadable files
Circuit board
Circuit board
Comments
Only logged in users can leave comments
issaom
4 Followers
•6 Projects
4
1
Anonymous user
4 years ago
How much did this cost? Also do you have any videos of this in English?