Components and supplies
Pololu maestro
SPMSA 330
Arduino Mega 2560
Camera OV7670 with Fifo
RGB Backlight LCD - 16x2
Tools and machines
Zmorph
Project description
Code
cameramaestro
arduino
1 2 3 4// pour voir la photo .yuv utliser le terminal et ecrire: 5// ffmpeg -f rawvideo -s 86x72 -pix_fmt yuyv422 -i /QQVGA0.YUV -f image2 -vcodec png /outputfile.png 6 7// le format utilis pour la camra est qqcif 86x72, les valeurs pour qqcif on t change dans le format qqvga 8 9#include "matrixpixel.h" 10#include <Wire.h>// pour communccation I2C pour parametrer la camera 11#include <SD.h>// pour la carte SD 12#include <SPI.h>// bus spi serie pour la maestro et bluetooth 13#include <LiquidCrystal.h>// pour le LCD afficheur 14LiquidCrystal lcd(4, 6, 10, 11, 12, 13);// initialize the library with the numbers of the interface pins 15#include "LcDef.h"// definition des valeurs de registre de la camera 16#include <PololuMaestro.h> // pour contrler les cartes servos 17 18#ifdef SERIAL_PORT_HARDWARE_OPEN 19 #define maestroSerial SERIAL_PORT_HARDWARE_OPEN 20#else 21 #include <SoftwareSerial.h> 22 SoftwareSerial maestroSerial(19, 18); 23#endif 24 25//* Next, create a Maestro object using the serial port. 26MiniMaestro maestro0(maestroSerial,255,12); 27MiniMaestro maestro1(maestroSerial,255,13); 28MiniMaestro maestro2(maestroSerial,255,14); 29MiniMaestro maestro3(maestroSerial,255,15); 30MiniMaestro maestro4(maestroSerial,255,16); 31MiniMaestro maestro5(maestroSerial,255,17); 32MiniMaestro maestro6(maestroSerial,255,18); 33MiniMaestro maestro7(maestroSerial,255,19); 34MiniMaestro maestro8(maestroSerial,255,20); 35MiniMaestro maestro9(maestroSerial,255,21); 36MiniMaestro maestro10(maestroSerial,255,22); 37MiniMaestro maestro11(maestroSerial,255,23); 38MiniMaestro maestro12(maestroSerial,255,24); 39MiniMaestro maestro13(maestroSerial,255,25); 40MiniMaestro maestro14(maestroSerial,255,26); 41MiniMaestro maestro15(maestroSerial,255,27); 42MiniMaestro maestro16(maestroSerial,255,28); 43MiniMaestro maestro17(maestroSerial,255,29); 44MiniMaestro maestro18(maestroSerial,255,30); 45MiniMaestro maestro19(maestroSerial,255,31); 46MiniMaestro maestro20(maestroSerial,255,32); 47MiniMaestro maestro21(maestroSerial,255,33); 48MiniMaestro maestro22(maestroSerial,255,34); 49MiniMaestro maestro23(maestroSerial,255,35); 50MiniMaestro device[24]{maestro0,maestro1,maestro2,maestro3,maestro4,maestro5,maestro6,maestro7,maestro8,maestro9,maestro10,maestro11,maestro12,maestro13,maestro14,maestro15,maestro16,maestro17,maestro18,maestro19,maestro20,maestro21,maestro22,maestro23}; 51 52//limite ne pas dpasser au tableau sinon le servos,les bras, les pices mobiles sont forces 53 54int degremin=25;// la plaque est tourne contre le haut 55int degremax=150;// la plaque est tourne contre le bas 56 57 58//limite ne pas dpasser par les servos sinon ils cassent, valeur plus extremes encore que degremin et degremax 59int valeurmax=map(degremax,0,180,2752,9600);// pour limiter les mouvements de degremin 160 degrmax 2400,8000 sont les valeurs min et max a donner auxservos pour 0 et 180 degrs 60int valeurmin=map(degremin,0,180,2752,9600);// pour limiter les mouvements de 30 160 degrs 2400,8000 sont les valeurs min et max a donner auxservos pour 0 et 180 degrs 61 62int valeur=valeurmin; 63const int chipSelect = 53; 64const int HardwareSSPin = 53; // For Arduino Mega 65 66 67 68// Serial Input 69const int BUFFERLENGTH = 255; 70char IncomingByte[BUFFERLENGTH]; // for incoming serial data 71 72// VGA Default 73int PHOTO_WIDTH = 640; 74int PHOTO_HEIGHT = 480; 75int PHOTO_BYTES_PER_PIXEL = 2; 76 77// Command and Parameter related Strings pour le choix de la balance des blancs, du temps de pose et du gain, du contour et du bruit, du niveau de noir 78String RawCommandLine = ""; 79String Command = "QVGA";// mais en fait c'est qqcif 72x86 80String FPSParam = "ThirtyFPS";//"NightMode" ou"ThirtyFPS" 81String AWBParam = "AAWB";//automatic white balance "AAWB" ou"SAWB"// AAWB est meilleur avec le tableau dans l'atelier avec peu de lumire 82String AECParam = "AveAEC";//automatic exposure control "AveAEC"(average) ou"HistAEC"(histogramme)// AveAEC est bien meilleur avec le tableau 83String YUVMatrixParam = "YUVMatrixOn";// ne rien mettre si on ne veut pas ou "YUVMatrixOn" 84String DenoiseParam = "DenoiseYes";//"DenoiseYes" ou"DenoiseNo"// un peu les deux pareils 85String EdgeParam = "EdgeYes";//"EdgeYes" ou"EdgeNo"// un peu les deux pareils 86String ABLCParam = "AblcOn";//"AblcOFF" ou"AblcON"// mieux avce AblOFF automatic black level control,dans la pnombre 87 88 89byte angle[24][24];// on ne peut pas avoir un tableau de byte car on additionne les valeurs de 9 pixels la fois donc 9*255, mais si on divise pixeldata/9 a fonctionne mais un peu moins prcis 90 91byte angleetalon90[24][24]; 92//byte angleetalonmax[24][24]; 93byte anglebefore[24][24]; 94 95int comptage = 0; 96boolean firstpicture=true; 97boolean macro=false; 98//// variable pour input 99const byte numChars = 32; 100char receivedChars[numChars]; 101char tempChars[numChars]; // temporary array for use when parsing 102char messageFromPC[numChars] = {0};// variables to hold the parsed data 103int integer0FromPC = 0; 104int integer1FromPC = 0; 105int integer2FromPC = 0; 106int integer3FromPC = 0; 107boolean newData = false; 108 109//// variable pour menu ett bouton 110int JoyStick_X = A0; //PS2 joystick X-axis is defined, ANALOG IN of Pin0 VRX sur A0 111int JoyStick_Y = A1; //PS2 joystick Y axis is defined, ANALOG IN of Pin1 VRY sur A1 112int JoyStick_Z = 2; //Defined PS2 joystick Z axis, pin2 SW sur 2 digital (pas analogique) 113int potentiometre=A7;// le pot est dans le pin analogique no 7 le pin du milieu du potentiometre sur A7 114int btpot; 115int btx; 116int bty; 117int btz; 118byte colonne=0; 119byte ligne=0; 120int nomenualain=0; 121byte colonneavant=0; 122byte ligneavant=0; 123//// fin de variable pour menu ett bouton 124 125 126 127 128 129enum ResolutionType 130{ 131 VGA, 132 VGAP, 133 QVGA, 134 QQVGA, 135 None 136}; 137 138ResolutionType Resolution = None; 139 140// Camera input/output pin connection to Arduino 141#define WRST 25 // Output Write Pointer Reset// ATTENTION sur le manuel 25 et 22 sont intervertis 142#define RRST 23 // Output Read Pointer Reset 143#define WEN 24 // Output Write Enable 144#define VSYNC 22 // Input Vertical Sync marking frame capture // ATTENTION sur le manuel 25 et 22 sont intervertis 145#define RCLK 26 // Output FIFO buffer output clock 146// set OE to low gnd 147 148// FIFO Ram input pins 149#define DO7 28 150#define DO6 29 151#define DO5 30 152#define DO4 31 153#define DO3 32 154#define DO2 33 155#define DO1 34 156#define DO0 35 157 158 159// SDCARD 160// MISO, MOSI, and SCK are also available in a consistent physical location on the ICSP header; 161// this is useful, for example, in designing a shield that works on the Uno and the Mega. 162// On the Arduino Mega, this is 163// 50 (MISO) 164// 51 (MOSI) 165// 52 (SCK) 166// 53 (SS) 167// VCC sur 5V 168//GND sur GND 169File myFile;// myFile=le fichier qu'on va lire sur la carte SD qui contient les valeurs 170 171 172 173byte ReadRegisterValue(int RegisterAddress) 174{ 175 byte data = 0; 176 177 Wire.beginTransmission(OV7670_I2C_ADDRESS); 178 Wire.write(RegisterAddress); 179 Wire.endTransmission(); 180 Wire.requestFrom(OV7670_I2C_ADDRESS, 1); 181 while(Wire.available() < 1); 182 data = Wire.read(); 183 184 return data; 185} 186 187void ReadRegisters() 188{ 189 byte data = 0; 190 191 data = ReadRegisterValue(CLKRC); 192 Serial.print(F("CLKRC = ")); 193 Serial.println(data,HEX); 194 195 data = ReadRegisterValue(COM7); 196 Serial.print(F("COM7 = ")); 197 Serial.println(data,HEX); 198 199 data = ReadRegisterValue(COM3); 200 Serial.print(F("COM3 = ")); 201 Serial.println(data,HEX); 202 203 data = ReadRegisterValue(COM14); 204 Serial.print(F("COM14 = ")); 205 Serial.println(data,HEX); 206 207 data = ReadRegisterValue(SCALING_XSC); 208 Serial.print(F("SCALING_XSC = ")); 209 Serial.println(data,HEX); 210 211 data = ReadRegisterValue(SCALING_YSC); 212 Serial.print(F("SCALING_YSC = ")); 213 Serial.println(data,HEX); 214 215 data = ReadRegisterValue(SCALING_DCWCTR); 216 Serial.print(F("SCALING_DCWCTR = ")); 217 Serial.println(data,HEX); 218 219 data = ReadRegisterValue(SCALING_PCLK_DIV); 220 Serial.print(F("SCALING_PCLK_DIV = ")); 221 Serial.println(data,HEX); 222 223 data = ReadRegisterValue(SCALING_PCLK_DELAY); 224 Serial.print(F("SCALING_PCLK_DELAY = ")); 225 Serial.println(data,HEX); 226 227 //data = ReadRegisterValue(COM10); 228 //Serial.print(F("COM10 (Vsync Polarity) = ")); 229 //Serial.println(data,HEX); 230 231 // default value D 232 data = ReadRegisterValue(TSLB); 233 Serial.print(F("TSLB (YUV Order- Higher Bit, Bit[3]) = ")); 234 Serial.println(data,HEX); 235 236 // default value 88 237 data = ReadRegisterValue(COM13); 238 Serial.print(F("COM13 (YUV Order - Lower Bit, Bit[1]) = ")); 239 Serial.println(data,HEX); 240 241 data = ReadRegisterValue(COM17); 242 Serial.print(F("COM17 (DSP Color Bar Selection) = ")); 243 Serial.println(data,HEX); 244 245 data = ReadRegisterValue(COM4); 246 Serial.print(F("COM4 (works with COM 17) = ")); 247 Serial.println(data,HEX); 248 249 data = ReadRegisterValue(COM15); 250 Serial.print(F("COM15 (COLOR FORMAT SELECTION) = ")); 251 Serial.println(data,HEX); 252 253 data = ReadRegisterValue(COM11); 254 Serial.print(F("COM11 (Night Mode) = ")); 255 Serial.println(data,HEX); 256 257 data = ReadRegisterValue(COM8); 258 Serial.print(F("COM8 (Color Control, AWB) = ")); 259 Serial.println(data,HEX); 260 261 data = ReadRegisterValue(HAECC7); 262 Serial.print(F("HAECC7 (AEC Algorithm Selection) = ")); 263 Serial.println(data,HEX); 264 265 data = ReadRegisterValue(GFIX); 266 Serial.print(F("GFIX = ")); 267 Serial.println(data,HEX); 268 269 270 // Window Output 271 data = ReadRegisterValue(HSTART); 272 Serial.print(F("HSTART = ")); 273 Serial.println(data,HEX); 274 //Serial.print(F(", ")); 275 //Serial.println(data, DEC); 276 277 data = ReadRegisterValue(HSTOP); 278 Serial.print(F("HSTOP = ")); 279 Serial.println(data,HEX); 280 281 data = ReadRegisterValue(HREF); 282 Serial.print(F("HREF = ")); 283 Serial.println(data,HEX); 284 285 data = ReadRegisterValue(VSTRT); 286 Serial.print(F("VSTRT = ")); 287 Serial.println(data,HEX); 288 289 data = ReadRegisterValue(VSTOP); 290 Serial.print(F("VSTOP = ")); 291 Serial.println(data,HEX); 292 293 data = ReadRegisterValue(VREF); 294 Serial.print(F("VREF = ")); 295 Serial.println(data,HEX); 296} 297 298 299void ResetCameraRegisters() 300{ 301 // Reset Camera Registers 302 // Reading needed to prevent error 303 byte data = ReadRegisterValue(COM7); 304 305 int result = OV7670WriteReg(COM7, COM7_VALUE_RESET ); 306 String sresult = ParseI2CResult(result); 307 Serial.println("RESETTING ALL REGISTERS BY SETTING COM7 REGISTER to 0x80: " + sresult); 308 309 // Delay at least 500ms 310 delay(500); 311} 312 313 314 315// Main Call to Setup the ov7670 Camera 316void SetupCamera() 317{ 318 Serial.println(F("In SetupCamera() ...")); 319 InitializeOV7670Camera(); 320} 321 322 323void InitializeOV7670Camera() 324{ 325 Serial.println(F("Initializing OV7670 Camera ...")); 326 327 //Set WRST to 0 and RRST to 0 , 0.1ms after power on. 328 int DurationMicroSecs = 1;// mais on peut mettre aussi 0 a va aussi 329 330 // Set mode for pins wither input or output 331 pinMode(WRST , OUTPUT); 332 pinMode(RRST , OUTPUT); 333 pinMode(WEN , OUTPUT); 334 pinMode(VSYNC, INPUT); 335 pinMode(RCLK , OUTPUT); 336 337 // FIFO Ram output pins 338 pinMode(DO7 , INPUT); 339 pinMode(DO6 , INPUT); 340 pinMode(DO5 , INPUT); 341 pinMode(DO4 , INPUT); 342 pinMode(DO3 , INPUT); 343 pinMode(DO2 , INPUT); 344 pinMode(DO1 , INPUT); 345 pinMode(DO0 , INPUT); 346 347 // Delay 1 ms 348 delay(1); 349 350 PulseLowEnabledPin(WRST, DurationMicroSecs); 351 352 //PulseLowEnabledPin(RRST, DurationMicroSecs); 353 // Need to clock the fifo manually to get it to reset 354 digitalWrite(RRST, LOW); 355 PulsePin(RCLK, DurationMicroSecs); 356 PulsePin(RCLK, DurationMicroSecs); 357 digitalWrite(RRST, HIGH); 358} 359 360void SetupCameraAdvancedAutoWhiteBalanceConfig()// utilis dans le format que j'utilise dans le choix de AAWB 361{ 362 int result = 0; 363 String sresult = ""; 364 365 Serial.println(F("........... Setting Camera Advanced Auto White Balance Configs ........")); 366 367 result = OV7670WriteReg(AWBC1, AWBC1_VALUE); 368 sresult = ParseI2CResult(result); 369 Serial.print(F("AWBC1: ")); 370 Serial.println(sresult); 371 372 result = OV7670WriteReg(AWBC2, AWBC2_VALUE); 373 sresult = ParseI2CResult(result); 374 Serial.print(F("AWBC2: ")); 375 Serial.println(sresult); 376 377 result = OV7670WriteReg(AWBC3, AWBC3_VALUE); 378 sresult = ParseI2CResult(result); 379 Serial.print(F("AWBC3: ")); 380 Serial.println(sresult); 381 382 result = OV7670WriteReg(AWBC4, AWBC4_VALUE); 383 sresult = ParseI2CResult(result); 384 Serial.print(F("AWBC4: ")); 385 Serial.println(sresult); 386 387 result = OV7670WriteReg(AWBC5, AWBC5_VALUE); 388 sresult = ParseI2CResult(result); 389 Serial.print(F("AWBC5: ")); 390 Serial.println(sresult); 391 392 result = OV7670WriteReg(AWBC6, AWBC6_VALUE); 393 sresult = ParseI2CResult(result); 394 Serial.print(F("AWBC6: ")); 395 Serial.println(sresult); 396 397 result = OV7670WriteReg(AWBC7, AWBC7_VALUE); 398 sresult = ParseI2CResult(result); 399 Serial.print(F("AWBC7: ")); 400 Serial.println(sresult); 401 402 result = OV7670WriteReg(AWBC8, AWBC8_VALUE); 403 sresult = ParseI2CResult(result); 404 Serial.print(F("AWBC8: ")); 405 Serial.println(sresult); 406 407 result = OV7670WriteReg(AWBC9, AWBC9_VALUE); 408 sresult = ParseI2CResult(result); 409 Serial.print(F("AWBC9: ")); 410 Serial.println(sresult); 411 412 result = OV7670WriteReg(AWBC10, AWBC10_VALUE); 413 sresult = ParseI2CResult(result); 414 Serial.print(F("AWBC10: ")); 415 Serial.println(sresult); 416 417 result = OV7670WriteReg(AWBC11, AWBC11_VALUE); 418 sresult = ParseI2CResult(result); 419 Serial.print(F("AWBC11: ")); 420 Serial.println(sresult); 421 422 result = OV7670WriteReg(AWBC12, AWBC12_VALUE); 423 sresult = ParseI2CResult(result); 424 Serial.print(F("AWBC12: ")); 425 Serial.println(sresult); 426 427 result = OV7670WriteReg(AWBCTR3, AWBCTR3_VALUE); 428 sresult = ParseI2CResult(result); 429 Serial.print(F("AWBCTR3: ")); 430 Serial.println(sresult); 431 432 result = OV7670WriteReg(AWBCTR2, AWBCTR2_VALUE); 433 sresult = ParseI2CResult(result); 434 Serial.print(F("AWBCTR2: ")); 435 Serial.println(sresult); 436 437 result = OV7670WriteReg(AWBCTR1, AWBCTR1_VALUE); 438 sresult = ParseI2CResult(result); 439 Serial.print(F("AWBCTR1: ")); 440 Serial.println(sresult); 441} 442 443void SetupCameraUndocumentedRegisters()// utilis dans le format que j'utilise 444{ 445 // Write(0xb0,0x84); //adding this improve the color a little bit 446 int result = 0; 447 String sresult = ""; 448 449 Serial.println(F("........... Setting Camera Undocumented Registers ........")); 450 result = OV7670WriteReg(0xB0, 0x84); 451 sresult = ParseI2CResult(result); 452 Serial.print(F("Setting B0 UNDOCUMENTED register to 0x84:= ")); 453 Serial.println(sresult); 454} 455 456void SetupCameraFor30FPS()// utilis dans le format que j'utilise 457{ 458 int result = 0; 459 String sresult = ""; 460 461 Serial.println(F("........... Setting Camera to 30 FPS ........")); 462 result = OV7670WriteReg(CLKRC, CLKRC_VALUE_30FPS); 463 sresult = ParseI2CResult(result); 464 Serial.print(F("CLKRC: ")); 465 Serial.println(sresult); 466 467 result = OV7670WriteReg(DBLV, DBLV_VALUE_30FPS); 468 sresult = ParseI2CResult(result); 469 Serial.print(F("DBLV: ")); 470 Serial.println(sresult); 471 472 result = OV7670WriteReg(EXHCH, EXHCH_VALUE_30FPS); 473 sresult = ParseI2CResult(result); 474 Serial.print(F("EXHCH: ")); 475 Serial.println(sresult); 476 477 result = OV7670WriteReg(EXHCL, EXHCL_VALUE_30FPS); 478 sresult = ParseI2CResult(result); 479 Serial.print(F("EXHCL: ")); 480 Serial.println(sresult); 481 482 result = OV7670WriteReg(DM_LNL, DM_LNL_VALUE_30FPS); 483 sresult = ParseI2CResult(result); 484 Serial.print(F("DM_LNL: ")); 485 Serial.println(sresult); 486 487 result = OV7670WriteReg(DM_LNH, DM_LNH_VALUE_30FPS); 488 sresult = ParseI2CResult(result); 489 Serial.print(F("DM_LNH: ")); 490 Serial.println(sresult); 491 492 result = OV7670WriteReg(COM11, COM11_VALUE_30FPS); 493 sresult = ParseI2CResult(result); 494 Serial.print(F("COM11: ")); 495 Serial.println(sresult); 496 497} 498 499void SetupCameraABLC()// utilis dans le format que j'utilise automatic black level calibration 500{ 501 int result = 0; 502 String sresult = ""; 503 504 // If ABLC is off then return otherwise 505 // turn on ABLC. 506 if (ABLCParam == "AblcOFF") 507 { 508 return; 509 } 510 511 Serial.println(F("........ Setting Camera ABLC .......")); 512 513 result = OV7670WriteReg(ABLC1, ABLC1_VALUE); 514 sresult = ParseI2CResult(result); 515 Serial.print(F("ABLC1: ")); 516 Serial.println(sresult); 517 518 result = OV7670WriteReg(THL_ST, THL_ST_VALUE); 519 sresult = ParseI2CResult(result); 520 Serial.print(F("THL_ST: ")); 521 Serial.println(sresult); 522} 523 524 525 526void SetupCameraAverageBasedAECAGC()// voir chapitre 3.3.4.1 de implementation-guide// utilis dans le format que j'utilise dans le choix de AveAEC 527{ 528 int result = 0; 529 String sresult = ""; 530 531 Serial.println(F("-------------- Setting Camera Average Based AEC/AGC Registers ---------------")); 532// il y a deux zones: la controlzone en dehors de laquelle aec(automatique exposure)et agc (automatic gain) sont augment ou diminu par de large pas 533// une fois dans la controlezone mais en dehors de la stable operatingregion les pas sont pkus petits, puis une fois dans la stable operating region il n'ya plus de changement de aec ni de agc 534// on peut donc dfinir les limites sup et inf des deux zones 535 536 result = OV7670WriteReg(AEW, AEW_VALUE);// stable operating region upper limit 537 sresult = ParseI2CResult(result); 538 Serial.print(F("AEW: ")); 539 Serial.println(sresult); 540 541 result = OV7670WriteReg(AEB, AEB_VALUE);// stable operating region lower limit 542 sresult = ParseI2CResult(result); 543 Serial.print(F("AEB: ")); 544 Serial.println(sresult); 545 546 result = OV7670WriteReg(VPT, VPT_VALUE);// control zone upper limit (VPT[7:4]) et lower limit sur VPT[3:0] 547 sresult = ParseI2CResult(result); 548 Serial.print(F("VPT: ")); 549 Serial.println(sresult); 550 551 result = OV7670WriteReg(HAECC7, HAECC7_VALUE_AVERAGE_AEC_ON);// average luminance calculation window (full frame ou center halfframe, ou ceter quarter frame) 552 sresult = ParseI2CResult(result); 553 Serial.print(F("HAECC7: ")); 554 Serial.println(sresult); 555} 556 557void SetCameraHistogramBasedAECAGC()// utilis dans le format que j'utilise dans le choix de HistAEC 558{ 559 int result = 0; 560 String sresult = ""; 561 562 Serial.println(F("-------------- Setting Camera Histogram Based AEC/AGC Registers ---------------")); 563 564 result = OV7670WriteReg(AEW, AEW_VALUE); 565 sresult = ParseI2CResult(result); 566 Serial.print(F("AEW: ")); 567 Serial.println(sresult); 568 569 result = OV7670WriteReg(AEB, AEB_VALUE); 570 sresult = ParseI2CResult(result); 571 Serial.print(F("AEB: ")); 572 Serial.println(sresult); 573 574 result = OV7670WriteReg(HAECC1, HAECC1_VALUE); 575 sresult = ParseI2CResult(result); 576 Serial.print(F("HAECC1: ")); 577 Serial.println(sresult); 578 579 result = OV7670WriteReg(HAECC2, HAECC2_VALUE); 580 sresult = ParseI2CResult(result); 581 Serial.print(F("HAECC2: ")); 582 Serial.println(sresult); 583 584 result = OV7670WriteReg(HAECC3, HAECC3_VALUE); 585 sresult = ParseI2CResult(result); 586 Serial.print(F("HAECC3: ")); 587 Serial.println(sresult); 588 589 result = OV7670WriteReg(HAECC4, HAECC4_VALUE); 590 sresult = ParseI2CResult(result); 591 Serial.print(F("HAECC4: ")); 592 Serial.println(sresult); 593 594 result = OV7670WriteReg(HAECC5, HAECC5_VALUE); 595 sresult = ParseI2CResult(result); 596 Serial.print(F("HAECC5: ")); 597 Serial.println(sresult); 598 599 result = OV7670WriteReg(HAECC6, HAECC6_VALUE); 600 sresult = ParseI2CResult(result); 601 Serial.print(F("HAECC6: ")); 602 Serial.println(sresult); 603 604 result = OV7670WriteReg(HAECC7, HAECC7_VALUE_HISTOGRAM_AEC_ON); 605 sresult = ParseI2CResult(result); 606 Serial.print(F("HAECC7: ")); 607 Serial.println(sresult); 608} 609 610 611void SetupCameraNightMode()// utilis dans le format que j'utilise, dans le choix de FPS mode 612{ 613 int result = 0; 614 String sresult = ""; 615 616 Serial.println(F("......... Turning NIGHT MODE ON ........")); 617 result = OV7670WriteReg(CLKRC, CLKRC_VALUE_NIGHTMODE_AUTO); 618 sresult = ParseI2CResult(result); 619 Serial.print(F("CLKRC: ")); 620 Serial.println(sresult); 621 622 result = OV7670WriteReg(COM11, COM11_VALUE_NIGHTMODE_AUTO); 623 sresult = ParseI2CResult(result); 624 Serial.print(F("COM11: ")); 625 Serial.println(sresult); 626} 627 628 629void SetupCameraSimpleAutomaticWhiteBalance()// utilis dans le format que j'utilise dans le choix de SAWB 630{ 631 /* 632 i2c_salve_Address = 0x42; 633 write_i2c(0x13, 0xe7); //AWB on 634 write_i2c(0x6f, 0x9f); // Simple AWB 635 */ 636 637 int result = 0; 638 String sresult = ""; 639 640 Serial.println(F("........... Setting Camera to Simple AWB ........")); 641 642 // COM8 643 //result = OV7670WriteReg(0x13, 0xE7); 644 result = OV7670WriteReg(COM8, COM8_VALUE_AWB_ON);// simple automatic white balance 645 sresult = ParseI2CResult(result); 646 Serial.print(F("COM8(0x13): ")); 647 Serial.println(sresult); 648 649 // AWBCTR0 650 //result = OV7670WriteReg(0x6f, 0x9f); 651 result = OV7670WriteReg(AWBCTR0, AWBCTR0_VALUE_NORMAL);// simple automatic white balance 652 sresult = ParseI2CResult(result); 653 Serial.print(F("AWBCTR0 Control Register 0(0x6F): ")); 654 Serial.println(sresult); 655} 656 657void SetupCameraAdvancedAutomaticWhiteBalance()// utilis dans le format que j'utilise dans le choix de AAWB 658{ 659 int result = 0; 660 String sresult = ""; 661 662 Serial.println(F("........... Setting Camera to Advanced AWB ........")); 663 664 // AGC, AWB, and AEC Enable 665 result = OV7670WriteReg(0x13, 0xE7);//0xE7 normalement , j'ai mis E6 pour desactiver le AEC 666 sresult = ParseI2CResult(result); 667 Serial.print(F("COM8(0x13): ")); 668 Serial.println(sresult); 669 670 // AWBCTR0 671 result = OV7670WriteReg(0x6f, 0x9E); 672 sresult = ParseI2CResult(result); 673 Serial.print(F("AWB Control Register 0(0x6F): ")); 674 Serial.println(sresult); 675} 676 677void SetupCameraGain()// utilis dans le format que j'utilise dans le choix de AWB SAWB ou AAWB 678{ 679 int result = 0; 680 String sresult = ""; 681 682 Serial.println(F("........... Setting Camera Gain ........")); 683 684 // Set Maximum Gain 685 //result = OV7670WriteReg(COM9, COM9_VALUE_MAX_GAIN_128X); 686 result = OV7670WriteReg(COM9, COM9_VALUE_4XGAIN); 687 //result = OV7670WriteReg(COM9, 0x18); 688 sresult = ParseI2CResult(result); 689 Serial.print(F("COM9: ")); 690 Serial.println(sresult); 691 692 // Set Blue Gain 693 //{ REG_BLUE, 0x40 }, 694 result = OV7670WriteReg(BLUE, BLUE_VALUE); 695 sresult = ParseI2CResult(result); 696 Serial.print(F("BLUE GAIN: ")); 697 Serial.println(sresult); 698 699 // Set Red Gain 700 //{ REG_RED, 0x60 }, 701 result = OV7670WriteReg(RED, RED_VALUE); 702 sresult = ParseI2CResult(result); 703 Serial.print(F("RED GAIN: ")); 704 Serial.println(sresult); 705 706 707 // Set Green Gain 708 //{ 0x6a, 0x40 }, 709 result = OV7670WriteReg(GGAIN, GGAIN_VALUE); 710 sresult = ParseI2CResult(result); 711 Serial.print(F("GREEN GAIN: ")); 712 Serial.println(sresult); 713 714 715 // Enable AWB Gain 716 // REG_COM16 0x41 /* Control 16 */ 717 // COM16_AWBGAIN 0x08 /* AWB gain enable */ 718 // { REG_COM16, COM16_AWBGAIN }, 719 result = OV7670WriteReg(COM16, COM16_VALUE); 720 sresult = ParseI2CResult(result); 721 Serial.print(F("COM16(ENABLE GAIN): ")); 722 Serial.println(sresult); 723 724} 725 726void SetCameraSaturationControl()// utilis dans le format que j'utilise 727{ 728 int result = 0; 729 String sresult = ""; 730 731 Serial.println(F("........... Setting Camera Saturation Level ........")); 732 result = OV7670WriteReg(SATCTR, SATCTR_VALUE); 733 sresult = ParseI2CResult(result); 734 Serial.print(F("SATCTR: ")); 735 Serial.println(sresult); 736} 737 738void SetCameraColorMatrixYUV()// utilis dans le format que j'utilise 739{ 740 int result = 0; 741 String sresult = ""; 742 743 Serial.println(F("........... Setting Camera Color Matrix for YUV ........")); 744 745 result = OV7670WriteReg(MTX1, MTX1_VALUE); 746 sresult = ParseI2CResult(result); 747 Serial.print(F("MTX1: ")); 748 Serial.println(sresult); 749 750 result = OV7670WriteReg(MTX2, MTX2_VALUE); 751 sresult = ParseI2CResult(result); 752 Serial.print(F("MTX2: ")); 753 Serial.println(sresult); 754 755 result = OV7670WriteReg(MTX3, MTX3_VALUE); 756 sresult = ParseI2CResult(result); 757 Serial.print(F("MTX3: ")); 758 Serial.println(sresult); 759 760 result = OV7670WriteReg(MTX4, MTX4_VALUE); 761 sresult = ParseI2CResult(result); 762 Serial.print(F("MTX4: ")); 763 Serial.println(sresult); 764 765 result = OV7670WriteReg(MTX5, MTX5_VALUE); 766 sresult = ParseI2CResult(result); 767 Serial.print(F("MTX5: ")); 768 Serial.println(sresult); 769 770 result = OV7670WriteReg(MTX6, MTX6_VALUE); 771 sresult = ParseI2CResult(result); 772 Serial.print(F("MTX6: ")); 773 Serial.println(sresult); 774 775 result = OV7670WriteReg(CONTRAS, CONTRAS_VALUE); 776 sresult = ParseI2CResult(result); 777 Serial.print(F("CONTRAS: ")); 778 Serial.println(sresult); 779 780 result = OV7670WriteReg(MTXS, MTXS_VALUE); 781 sresult = ParseI2CResult(result); 782 Serial.print(F("MTXS: ")); 783 Serial.println(sresult); 784} 785 786void SetCameraFPSMode()// utilis dans le format que j'utilise 787{ 788 // Set FPS for Camera 789 if (FPSParam == "ThirtyFPS") 790 { 791 SetupCameraFor30FPS(); 792 793 } 794 else 795 if (FPSParam == "NightMode") 796 { 797 SetupCameraNightMode(); 798 } 799} 800 801void SetCameraAEC()// utilis dans le format que j'utilise 802{ 803 // Process AEC 804 if (AECParam == "AveAEC") 805 { 806 // Set Camera's Average AEC/AGC Parameters 807 SetupCameraAverageBasedAECAGC(); 808 } 809 else 810 if (AECParam == "HistAEC") 811 { 812 // Set Camera AEC algorithim to Histogram 813 SetCameraHistogramBasedAECAGC(); 814 } 815} 816 817void SetupCameraAWB()// utilis dans le format que j'utilise 818{ 819 // Set AWB Mode 820 if (AWBParam == "SAWB") 821 { 822 // Set Simple Automatic White Balance 823 SetupCameraSimpleAutomaticWhiteBalance(); // OK 824 825 // Set Gain Config 826 SetupCameraGain(); 827 } 828 else 829 if (AWBParam == "AAWB") 830 { 831 // Set Advanced Automatic White Balance 832 SetupCameraAdvancedAutomaticWhiteBalance(); // ok 833 834 // Set Camera Automatic White Balance Configuration 835 SetupCameraAdvancedAutoWhiteBalanceConfig(); // ok 836 837 // Set Gain Config 838 SetupCameraGain(); 839 } 840} 841 842 843void SetupCameraDenoise() 844{ 845 int result = 0; 846 String sresult = ""; 847 848 Serial.println(F("........... Setting Camera Denoise ........")); 849 850 result = OV7670WriteReg(DNSTH, DNSTH_VALUE); 851 sresult = ParseI2CResult(result); 852 Serial.print(F("DNSTH: ")); 853 Serial.println(sresult); 854 855 result = OV7670WriteReg(REG77, REG77_VALUE); 856 sresult = ParseI2CResult(result); 857 Serial.print(F("REG77: ")); 858 Serial.println(sresult); 859} 860 861 862void SetupCameraEdgeEnhancement() 863{ 864 int result = 0; 865 String sresult = ""; 866 867 Serial.println(F("........... Setting Camera Edge Enhancement ........")); 868 869 result = OV7670WriteReg(EDGE, EDGE_VALUE); 870 sresult = ParseI2CResult(result); 871 Serial.print(F("EDGE: ")); 872 Serial.println(sresult); 873 874 result = OV7670WriteReg(REG75, REG75_VALUE); 875 sresult = ParseI2CResult(result); 876 Serial.print(F("REG75: ")); 877 Serial.println(sresult); 878 879 result = OV7670WriteReg(REG76, REG76_VALUE); 880 sresult = ParseI2CResult(result); 881 Serial.print(F("REG76: ")); 882 Serial.println(sresult); 883} 884 885 886 887void SetupCameraDenoiseEdgeEnhancement()// utilis dans le format que j'utilise 888{ 889 int result = 0; 890 String sresult = ""; 891 892 if ((DenoiseParam == "DenoiseYes")&& 893 (EdgeParam == "EdgeYes")) 894 { 895 SetupCameraDenoise(); 896 SetupCameraEdgeEnhancement(); 897 result = OV7670WriteReg(COM16, COM16_VALUE_DENOISE_ON__EDGE_ENHANCEMENT_ON__AWBGAIN_ON); 898 sresult = ParseI2CResult(result); 899 Serial.print(F("COM16: ")); 900 Serial.println(sresult); 901 } 902 else 903 if ((DenoiseParam == "DenoiseYes")&& 904 (EdgeParam == "EdgeNo")) 905 { 906 SetupCameraDenoise(); 907 result = OV7670WriteReg(COM16, COM16_VALUE_DENOISE_ON__EDGE_ENHANCEMENT_OFF__AWBGAIN_ON); 908 sresult = ParseI2CResult(result); 909 Serial.print(F("COM16: ")); 910 Serial.println(sresult); 911 } 912 else 913 if ((DenoiseParam == "DenoiseNo")&& 914 (EdgeParam == "EdgeYes")) 915 { 916 SetupCameraEdgeEnhancement(); 917 result = OV7670WriteReg(COM16, COM16_VALUE_DENOISE_OFF__EDGE_ENHANCEMENT_ON__AWBGAIN_ON); 918 sresult = ParseI2CResult(result); 919 Serial.print(F("COM16: ")); 920 Serial.println(sresult); 921 } 922} 923 924 925/* 926void SetCameraGamma() 927{ 928 int result = 0; 929 String sresult = ""; 930 931 Serial.println(F("........... Setting Camera Gamma ........")); 932 933 result = OV7670WriteReg(SLOP, SLOP_VALUE); 934 sresult = ParseI2CResult(result); 935 Serial.print(F("SLOP: ")); 936 Serial.println(sresult); 937 result = OV7670WriteReg(GAM1, GAM1_VALUE); 938 sresult = ParseI2CResult(result); 939 Serial.print(F("GAM1: ")); 940 Serial.println(sresult); 941 942 result = OV7670WriteReg(GAM2, GAM2_VALUE); 943 sresult = ParseI2CResult(result); 944 Serial.print(F("GAM2: ")); 945 Serial.println(sresult); 946 947 result = OV7670WriteReg(GAM3, GAM3_VALUE); 948 sresult = ParseI2CResult(result); 949 Serial.print(F("GAM3: ")); 950 Serial.println(sresult); 951 952 result = OV7670WriteReg(GAM4, GAM4_VALUE); 953 sresult = ParseI2CResult(result); 954 Serial.print(F("GAM4: ")); 955 Serial.println(sresult); 956 957 result = OV7670WriteReg(GAM5, GAM5_VALUE); 958 sresult = ParseI2CResult(result); 959 Serial.print(F("GAM5: ")); 960 Serial.println(sresult); 961 962 result = OV7670WriteReg(GAM6, GAM6_VALUE); 963 sresult = ParseI2CResult(result); 964 Serial.print(F("GAM6: ")); 965 Serial.println(sresult); 966 967 result = OV7670WriteReg(GAM7, GAM7_VALUE); 968 sresult = ParseI2CResult(result); 969 Serial.print(F("GAM7: ")); 970 Serial.println(sresult); 971 972 result = OV7670WriteReg(GAM8, GAM8_VALUE); 973 sresult = ParseI2CResult(result); 974 Serial.print(F("GAM8: ")); 975 Serial.println(sresult); 976 977 result = OV7670WriteReg(GAM9, GAM9_VALUE); 978 sresult = ParseI2CResult(result); 979 Serial.print(F("GAM9: ")); 980 Serial.println(sresult); 981 982 result = OV7670WriteReg(GAM10, GAM10_VALUE); 983 sresult = ParseI2CResult(result); 984 Serial.print(F("GAM10: ")); 985 Serial.println(sresult); 986 987 result = OV7670WriteReg(GAM11, GAM11_VALUE); 988 sresult = ParseI2CResult(result); 989 Serial.print(F("GAM11: ")); 990 Serial.println(sresult); 991 992 result = OV7670WriteReg(GAM12, GAM12_VALUE); 993 sresult = ParseI2CResult(result); 994 Serial.print(F("GAM12: ")); 995 Serial.println(sresult); 996 997 result = OV7670WriteReg(GAM13, GAM13_VALUE); 998 sresult = ParseI2CResult(result); 999 Serial.print(F("GAM13: ")); 1000 Serial.println(sresult); 1001 1002 result = OV7670WriteReg(GAM14, GAM14_VALUE); 1003 sresult = ParseI2CResult(result); 1004 Serial.print(F("GAM14: ")); 1005 Serial.println(sresult); 1006 1007 result = OV7670WriteReg(GAM15, GAM15_VALUE); 1008 sresult = ParseI2CResult(result); 1009 Serial.print(F("GAM15: ")); 1010 Serial.println(sresult); 1011} 1012*/ 1013 1014 1015 1016void SetupCameraArrayControl()// il semble que pas utilis dans le format que j'utilise 1017{ 1018 int result = 0; 1019 String sresult = ""; 1020 1021 Serial.println(F("........... Setting Camera Array Control ........")); 1022 1023 result = OV7670WriteReg(CHLF, CHLF_VALUE); 1024 sresult = ParseI2CResult(result); 1025 Serial.print(F("CHLF: ")); 1026 Serial.println(sresult); 1027 1028 result = OV7670WriteReg(ARBLM, ARBLM_VALUE); 1029 sresult = ParseI2CResult(result); 1030 Serial.print(F("ARBLM: ")); 1031 Serial.println(sresult); 1032} 1033 1034 1035 1036void SetupCameraADCControl()// utilis dans le format que j'utilise 1037{ 1038 int result = 0; 1039 String sresult = ""; 1040 1041 Serial.println(F("........... Setting Camera ADC Control ........")); 1042 1043 result = OV7670WriteReg(ADCCTR1, ADCCTR1_VALUE); 1044 sresult = ParseI2CResult(result); 1045 Serial.print(F("ADCCTR1: ")); 1046 Serial.println(sresult); 1047 1048 result = OV7670WriteReg(ADCCTR2, ADCCTR2_VALUE); 1049 sresult = ParseI2CResult(result); 1050 Serial.print(F("ADCCTR2: ")); 1051 Serial.println(sresult); 1052 1053 result = OV7670WriteReg(ADC, ADC_VALUE); 1054 sresult = ParseI2CResult(result); 1055 Serial.print(F("ADC: ")); 1056 Serial.println(sresult); 1057 1058 result = OV7670WriteReg(ACOM, ACOM_VALUE); 1059 sresult = ParseI2CResult(result); 1060 Serial.print(F("ACOM: ")); 1061 Serial.println(sresult); 1062 1063 result = OV7670WriteReg(OFON, OFON_VALUE); 1064 sresult = ParseI2CResult(result); 1065 Serial.print(F("OFON: ")); 1066 Serial.println(sresult); 1067} 1068 1069// special effects modify the MANU and MANV registers to override the computed values 1070// the TSLB is setup for various bit patters having to do with negative etc. 1071void specialEffects(){ 1072 1073 byte r_tslb = 0x10;// pour black and white 1074 byte r_manu = 0x80;// pour black and white 1075 byte r_manv = 0x80;// pour black and white 1076 1077 1078// byte r_tslb = 0x30;// pour black and white negative 1079// byte r_manu = 0x80;// pour black and white negative 1080// byte r_manv = 0x80;// pour black and white negative 1081// 1082// 1083// byte r_tslb = 0x20;// color negative 1084// byte r_manu = 0x80;// color negative 1085// byte r_manv = 0x80;// color negative 1086 1087 1088 1089 byte temp; 1090 temp = ReadRegisterValue(TSLB); 1091 temp = temp & 0xCF; // mask out bits 5 & 4 1092 temp = temp | r_tslb; 1093 OV7670WriteReg(TSLB,temp); 1094 OV7670WriteReg(MANU,r_manu); 1095 OV7670WriteReg(MANV,r_manv); 1096} 1097//******************************************************************************************************** 1098//******************************************************************************************************** 1099//******************************************************************************************************** 1100//******************************************************************************************************** 1101//******************************************************************************************************** 1102void SetupOV7670ForQQVGAYUV()// mais en fait c'est qqcif (86x72)qui sera configur 1103{ 1104 int result = 0; 1105 String sresult = ""; 1106 1107 Serial.println(F("--------------------------- Setting Camera for QQVGA YUV ---------------------------")); 1108 1109 1110 PHOTO_WIDTH = 86;// pour qqcif avec 86 au lieu de 88 1111 PHOTO_HEIGHT = 72; 1112 PHOTO_BYTES_PER_PIXEL = 2; 1113 1114 Serial.print(F("Photo Width = ")); 1115 Serial.println(PHOTO_WIDTH); 1116 1117 Serial.print(F("Photo Height = ")); 1118 Serial.println(PHOTO_HEIGHT); 1119 1120 Serial.print(F("Bytes Per Pixel = ")); 1121 Serial.println(PHOTO_BYTES_PER_PIXEL); 1122 1123 1124 Serial.println(F("........... Setting Basic QQVGA Parameters ........")); 1125 1126 result = OV7670WriteReg(CLKRC, CLKRC_VALUE_QQVGA); 1127 sresult = ParseI2CResult(result); 1128 Serial.print(F("CLKRC: ")); 1129 Serial.println(sresult); 1130 1131 result = OV7670WriteReg(COM7, COM7_VALUE_QQVGA ); 1132 //result = OV7670WriteReg(COM7, COM7_VALUE_QQVGA_COLOR_BAR ); 1133 sresult = ParseI2CResult(result); 1134 Serial.print(F("COM7: ")); 1135 Serial.println(sresult); 1136 1137 result = OV7670WriteReg(COM3, COM3_VALUE_QQVGA); 1138 sresult = ParseI2CResult(result); 1139 Serial.print(F("COM3: ")); 1140 Serial.println(sresult); 1141 1142 result = OV7670WriteReg(COM14, COM14_VALUE_QQVGA ); 1143 sresult = ParseI2CResult(result); 1144 Serial.print(F("COM14: ")); 1145 Serial.println(sresult); 1146 1147 result = OV7670WriteReg(SCALING_XSC,SCALING_XSC_VALUE_QQVGA ); 1148 sresult = ParseI2CResult(result); 1149 Serial.print(F("SCALING_XSC: ")); 1150 Serial.println(sresult); 1151 1152 result = OV7670WriteReg(SCALING_YSC,SCALING_YSC_VALUE_QQVGA ); 1153 sresult = ParseI2CResult(result); 1154 Serial.print(F("SCALING_YSC: ")); 1155 Serial.println(sresult); 1156 1157 result = OV7670WriteReg(SCALING_DCWCTR, SCALING_DCWCTR_VALUE_QQVGA ); 1158 sresult = ParseI2CResult(result); 1159 Serial.print(F("SCALING_DCWCTR: ")); 1160 Serial.println(sresult); 1161 1162 result = OV7670WriteReg(SCALING_PCLK_DIV, SCALING_PCLK_DIV_VALUE_QQVGA); 1163 sresult = ParseI2CResult(result); 1164 Serial.print(F("SCALING_PCLK_DIV: ")); 1165 Serial.println (sresult); 1166 1167 result = OV7670WriteReg(SCALING_PCLK_DELAY,SCALING_PCLK_DELAY_VALUE_QQVGA ); 1168 sresult = ParseI2CResult(result); 1169 Serial.print(F("SCALING_PCLK_DELAY: ")); 1170 Serial.println(sresult); 1171 1172 // YUV order control change from default use with COM13 1173 result = OV7670WriteReg(TSLB, TSLB_VALUE_YUYV_AUTO_OUTPUT_WINDOW_DISABLED); // Works 1174 sresult = ParseI2CResult(result); 1175 Serial.print(F("TSLB: ")); 1176 Serial.println(sresult); 1177 1178 //COM13 1179 //result = OV7670WriteReg(COM13, COM13_VALUE_GAMMA_YUYV); 1180 //result = OV7670WriteReg(COM13, COM13_VALUE_DEFAULT); 1181 //result = OV7670WriteReg(COM13, COM13_VALUE_GAMMA_YVYU); 1182 //result = OV7670WriteReg(COM13, COM13_VALUE_NOGAMMA_YUYV); 1183 //result = OV7670WriteReg(COM13, COM13_VALUE_YUYV_UVSATAUTOADJ_ON); 1184 // { REG_COM13, /*0xc3*/0x48 } // error in datasheet bit 3 controls YUV order 1185 //result = OV7670WriteReg(COM13, 0x48); 1186 1187 1188 result = OV7670WriteReg(COM13, 0xC8); // Gamma Enabled, UV Auto Adj On 1189 sresult = ParseI2CResult(result); 1190 Serial.print(F("COM13: ")); 1191 Serial.println(sresult); 1192 1193 // COM17 - DSP Color Bar Enable/Disable 1194 // 0000 1000 => to Enable 1195 // 0x08 1196 // COM17_VALUE 0x08 // Activate Color Bar for DSP 1197 //result = OV7670WriteReg(COM17, COM17_VALUE_AEC_NORMAL_COLOR_BAR); 1198 result = OV7670WriteReg(COM17, COM17_VALUE_AEC_NORMAL_NO_COLOR_BAR); 1199 sresult = ParseI2CResult(result); 1200 Serial.print(F("COM17: ")); 1201 Serial.println(sresult); 1202 1203 1204 // Set Additional Parameters avec les choix en dbut de programme 1205 1206//vertical flip____________________________________________________ 1207setReg(0x1E,16);// bit[4] 1 renverse le haut et le bas 1208//__________________________________________________________________ 1209 1210 1211//// essais de banding---------------------------------------------- 1212//// detetction 50hz ou 60 hz des lumires 1213// clearReg(COM11,16);// bit 4 1 1214// clearReg(COM11,8);// bit 3 1 1215// clearReg(COM8,32);// bit 5 1 1216// // request 50 Hertz banding 1217// setReg(COM11,8);// bit3 1 1218// setReg(COM8,32);// bit 5 1 1219// // request 60 Hertz banding 1220// setReg(COM8,32);// bit 5 1 1221// // request auto detect of banding frequency 1222// setReg(COM11,16);// bit 4 1 1223// 1224//// fin essais de banding------------------------------------------- 1225 1226 1227 1228//specialEffects();// pour black and white 1229 1230 1231 // Set Camera Frames per second 1232 SetCameraFPSMode(); // le choix entre Setupcamera30FPS ou Nightmode 1233 1234 // Set Camera Automatic Exposure Control ********************* 1235 SetCameraAEC(); // si il y a surexposition la prochaine capture sera plus fonce, avec choix entre averageaecagc ou histaec 1236 1237 // Set Camera Automatic White Balance ******************** 1238 SetupCameraAWB(); // il change en cours de route le blanc de rfrence, acex choix entre SAWB et AAWB 1239 1240 // Setup Undocumented Registers - Needed Minimum 1241 SetupCameraUndocumentedRegisters(); 1242 1243 1244 // Set Color Matrix for YUV 1245 if (YUVMatrixParam == "YUVMatrixOn") 1246 { 1247 SetCameraColorMatrixYUV(); 1248 } 1249 1250 // Set Camera Saturation******************** 1251 SetCameraSaturationControl(); 1252 1253 // Denoise and Edge Enhancement******************** 1254 SetupCameraDenoiseEdgeEnhancement(); // avec choix entre denoise etou ou pas du tout de edge enhancement 1255 1256 // Set New Gamma Values 1257 //SetCameraGamma(); 1258 1259 // Set Array Control************************ 1260 SetupCameraArrayControl();//desactiv pour essais 1261 1262 // Set ADC Control************************ 1263 SetupCameraADCControl();//desactiv pour essais 1264 1265 // Set Automatic Black Level Calibration************************ 1266 SetupCameraABLC();//desactiv pour essais 1267 1268 1269 Serial.println(F("........... Setting Camera Window Output Parameters ........")); 1270 1271 // Change Window Output parameters after custom scaling 1272 result = OV7670WriteReg(HSTART, HSTART_VALUE_QQVGA ); 1273 sresult = ParseI2CResult(result); 1274 Serial.print(F("HSTART: ")); 1275 Serial.println(sresult); 1276 1277 result = OV7670WriteReg(HSTOP, HSTOP_VALUE_QQVGA ); 1278 sresult = ParseI2CResult(result); 1279 Serial.print(F("HSTOP: ")); 1280 Serial.println(sresult); 1281 1282 result = OV7670WriteReg(HREF, HREF_VALUE_QQVGA ); 1283 sresult = ParseI2CResult(result); 1284 Serial.print(F("HREF: ")); 1285 Serial.println(sresult); 1286 1287 result = OV7670WriteReg(VSTRT, VSTRT_VALUE_QQVGA ); 1288 sresult = ParseI2CResult(result); 1289 Serial.print(F("VSTRT: ")); 1290 Serial.println(sresult); 1291 1292 result = OV7670WriteReg(VSTOP, VSTOP_VALUE_QQVGA ); 1293 sresult = ParseI2CResult(result); 1294 Serial.print(F("VSTOP: ")); 1295 Serial.println(sresult); 1296 1297 result = OV7670WriteReg(VREF, VREF_VALUE_QQVGA ); 1298 sresult = ParseI2CResult(result); 1299 Serial.print(F("VREF: ")); 1300 Serial.println(sresult); 1301} 1302 1303void CaptureOV7670Frame() 1304{ 1305 unsigned long DurationStart = 0; 1306 unsigned long DurationStop = 0; 1307 unsigned long TimeForCaptureStart = 0; 1308 unsigned long TimeForCaptureEnd = 0; 1309 unsigned long ElapsedTime = 0; 1310 1311// //Capture one frame into FIFO memory 1312// 1313// // 0. Initialization. 1314// Serial.println(); 1315// Serial.println(F("Starting Capture of Photo ...")); 1316 //TimeForCaptureStart = millis(); 1317 1318 // 1. Wait for VSync to pulse to indicate the start of the image 1319 DurationStart = pulseIn(VSYNC, LOW); 1320 1321 // 2. Reset Write Pointer to 0. Which is the beginning of frame 1322 PulseLowEnabledPin(WRST, 1); // en fait 1 microsecond va aussi; 3 microseconds + 3 microseconds=6 for error factor on Arduino on pulse bas pendant 1 microseconds puis haut pendant 1 microseconds 1323 1324 // 3. Set FIFO Write Enable to active (high) so that image can be written to ram 1325 digitalWrite(WEN, HIGH); 1326 1327 // 4. Wait for VSync to pulse again to indicate the end of the frame capture 1328 DurationStop = pulseIn(VSYNC, LOW); 1329 1330 // 5. Set FIFO Write Enable to nonactive (low) so that no more images can be written to the ram 1331 digitalWrite(WEN, LOW); 1332 1333 // 6. Print out Stats 1334 //TimeForCaptureEnd = millis(); 1335 // ElapsedTime = TimeForCaptureEnd - TimeForCaptureStart;// environ 100 miliseconds entre chaque capture 1336 1337 1338 // 7. WAIT so that new data can appear on output pins Read new data. 1339 //delay(1); 1340 1341} 1342 1343 1344 1345// Converts pin HIGH/LOW values on pins at positions 0-7 to a corresponding byte value 1346byte ConvertPinValueToByteValue(int PinValue, int PinPosition) 1347{ 1348 byte ByteValue = 0; 1349 if (PinValue == HIGH) 1350 { 1351 ByteValue = 1 << PinPosition; 1352 } 1353 1354 return ByteValue; 1355} 1356 1357void ReadTransmitCapturedFrame() 1358{ 1359 // Read captured frame from FIFO memory and send each byte as it is read to the Android controller 1360 // via bluetooth. 1361 1362 // Set Output Enable OE to active (low). 1363 // * Make sure to connect the OE output to ground. 1364 1365 // Reset the FIFO read pointer by setting RRST to active (low) then bringing it back to high. 1366 // *Done from previous CaptureOV7670Frame() assuming WRST and RRST are tied together. 1367 1368 // Read in the QQVGA image that is captured in the camera buffer by reading in the 38400 bytes that make up the 1369 // YUV photo 1370 1371byte PixelData = 0; 1372 byte PinVal7 = 0; 1373 byte PinVal6 = 0; 1374 byte PinVal5 = 0; 1375 byte PinVal4 = 0; 1376 byte PinVal3 = 0; 1377 byte PinVal2 = 0; 1378 byte PinVal1 = 0; 1379 byte PinVal0 = 0; 1380 1381 // Set Read Buffer Pointer to start of frame 1382 digitalWrite(RRST, LOW); 1383 1384 PulsePin(RCLK, 1); // on pulse haut pendant 1 microseconds puis bas pendant 1 microseconds 1385 PulsePin(RCLK, 1); 1386 PulsePin(RCLK, 1); 1387 digitalWrite(RRST, HIGH); 1388 1389 1390 1391 1392 1393 1394 //unsigned long ByteCounter = 0; 1395 1396 for(byte ii=0;ii<24;ii++){ 1397 for(byte jj=0;jj<24;jj++){angle[ii][jj]=0;}}//mise zero des angles 1398 1399 for (byte height = 0; height < PHOTO_HEIGHT; height++) 1400 { 1401 1402 for (byte width = 0; width < PHOTO_WIDTH; width++) 1403 { 1404// for (byte bytenumber = 0; bytenumber < PHOTO_BYTES_PER_PIXEL; bytenumber++)// je n'utilise plus le contrle du premier byte car j'utilise un deuxime PulsePin(RCLK, 1); sans lire les 8 digital read , juste aprs avoir lu le premier byte 1405// { 1406 // Pulse the read clock RCLK to bring in new byte of data. 1407 // 7ns for RCLK High Pulse Width and Low Pulse Width .007 micro secs 1408 PulsePin(RCLK, 1); //pour lire le byte 1409 1410 // Convert Pin values to byte values for pins 0-7 of incoming pixel byte 1411 PinVal7 = ConvertPinValueToByteValue(digitalRead(DO7), 7); 1412 PinVal6 = ConvertPinValueToByteValue(digitalRead(DO6), 6); 1413 PinVal5 = ConvertPinValueToByteValue(digitalRead(DO5), 5); 1414 PinVal4 = ConvertPinValueToByteValue(digitalRead(DO4), 4); 1415 PinVal3 = ConvertPinValueToByteValue(digitalRead(DO3), 3); 1416 PinVal2 = ConvertPinValueToByteValue(digitalRead(DO2), 2); 1417 PinVal1 = ConvertPinValueToByteValue(digitalRead(DO1), 1); 1418 PinVal0 = ConvertPinValueToByteValue(digitalRead(DO0), 0); 1419 1420 // Combine individual data from each pin into composite data in the form of a single byte 1421 PixelData = PinVal7 | PinVal6 | PinVal5 | PinVal4 | PinVal3 | PinVal2 | PinVal1 | PinVal0; 1422 1423 1424 1425 PulsePin(RCLK, 1); // pour passer au second byte qui ne sera pas lu de toute faon car il contient U ou V mais pas Y dans le format YUV (un coup YU un coup YV) 1426// un pixel sur deux car le premier est la valeur Y de luminosit puis U ou v pour la couleur 1427 1428 1429 //on prend 84/3=28 et 72/3 =24 pixel pour 3x3 pixel sans aggrandissement si on est 24x28, mais la largeur est 86 1430 1431if(macro==false){ 1432 if((width<75)&&(width>2)){// la premire colonne est noir il faut passer les 3 premierspixels et au lieu de 0 72 on va de 3 75= 72 pixel/3 =24 1433//angle[height/3][((width)/3)-1]=angle[height/3][((width)/3)-1]+PixelData; 1434angle[height/3][((width)/3)-1]=angle[height/3][((width)/3)-1]+(PixelData/9); //permet d'avoir un tableau de byte au lieu de int, mais du coup c'est moins prcis 1435 } 1436} 1437else{// camera macro on ne prend qu'une partie de l'image 1438if((width>31)&&(width<56)&&(height>24)&&(height<49)) 1439angle[height-25][width-32]=PixelData; 1440 1441} 1442 1443 1444 1445 1446 1447//*******************image rabote en deux 1448//if((width<66)&&(width>=18)&&(height>=12)&&(height<60)){ 1449//angle[(height/2)-6][((width)/2)-9]=angle[(height/2)-6][((width)/2)-9]+PixelData; 1450//} 1451//**************************************** 1452 1453//// pour envoi des pixels sur processing envoicamera86x72surprocess 1454//Serial.print(PixelData);// 1455//Serial.print(",");// angle,x,y avec un retour la ligne println('\ 1456' sur processing) 1457//Serial.print(width); 1458//Serial.print(","); 1459//Serial.println(height); 1460// fin de pour envoi des pixels sur processing 1461 1462 1463 1464 } 1465 1466 } 1467 1468} 1469 1470//******************************************************************************************************************************* 1471//******************************************************************************************************************************* 1472//******************************************************************************************************************************* 1473//******************************************************************************************************************************* 1474//******************************************************************************************************************************* 1475//******************************************************************************************************************************* 1476void TakePhoto() 1477{ 1478lcdaffiche("initilisation","de la camera"); 1479 1480touslesservosacetangle(90,80);//acceleration 30 va bien, mais 80 c'est trs ractif 1481for(int y=0;y<24;y++){ // pour tousles mettre 90 selon l'angle etalon et surtout ajuster l'acceleration 1482 for(int x=0;x<24;x++){ 1483 anglebefore[y][x]=0;// il faut les mettre zero au dpart 1484}} 1485 1486firstpicture=true; 1487comptage=0; 1488int seuil=25; 1489 1490while(nomenualain==3){ 1491 1492 1493// 1494bty=analogRead(JoyStick_Y); 1495if(bty<400){seuil=seuil+5;seuil=constrain(seuil,5,200); 1496lcdaffiche("seuil=",String(seuil));} 1497if(bty>800){seuil=seuil-5;seuil=constrain(seuil,5,200); 1498lcdaffiche("seuil=",String(seuil));} 1499 1500 1501 1502 CaptureOV7670Frame(); 1503 1504 ReadTransmitCapturedFrame(); 1505 1506 1507 1508 1509for(byte y=0;y<24;y++){ 1510 for(byte x=0;x<24;x++){ 1511//angle[(23-y)][x]=angle[(23-y)][x]/9;// il faut diviser par 9 car le ReadTransmitCapturedFrame() enregistre la valeur angle de 3x3 pixels 1512// si on ne divise pas par 9 c'est que le readtransmitcapture divise dj en 9 mais du coup c'est un peu moins prcis (mais a ne se voit pas) avantage car on utilise des bytes au lieu de int 1513//int k=(angle[(23-y)][x]/9);// pour image sans soustraction de la 5me image 1514 1515int k=abs((angle[y][x])-anglebefore[y][x]);// pour n'avoir que la diffrence par rapport la 5me prise de vue 1516k=k*3;// pour augmenter la diffrence entre le blanc et le noir 1517k=constrain(k,0,255);// pour viter que a dpasse car k*3 au dbut 1518 1519if(k>seuil){valeur=70;k=250;}// si on ne met pas a , tous les servos ont tendansce a tre boug un peu en fct de la luminosit 1520else{valeur=140;k=0;} 1521 1522 1523//envoiimagesurprocessing(k,x,y);// pour visualiser l'image , mais attention a raleinti 1524 1525 1526//**************************** pour envoi de l'angle sur les servos*********************** 1527if (firstpicture==false){ 1528//valeur=map(k, 255, 0, 70, 140);// pour un mouvement proportionnelle la brillance,de 40 degremax et invers le 255 donnera 40 degr 1529 1530valeur=(valeur-90)+ angleetalon90[y][x];// 1531valeur=constrain(valeur, degremin, degremax); 1532valeur=map(valeur, 0, 180, valeurmin, valeurmax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 1533device[x].setTarget(y, valeur); 1534 1535 1536} 1537//***************************************************************************************** 1538 1539 } 1540} 1541 1542 1543 1544if (firstpicture==true){ 1545int u=comptage; 1546 comptage=u+1; 1547 lcdaffiche(String(comptage),""); 1548 if(comptage==15){// il faut attendre 15x le temps que la camera s'ajuste au mieux 1549 for(byte y=0;y<24;y++){ 1550 for(byte x=0;x<24;x++){ 1551 anglebefore[y][x]=angle[y][x]; //pour 3x3 pour le cas ou on augmente pas le contraste 1552 1553 }} 1554 1555 1556 firstpicture=false; 1557lcdaffiche("ready","<-"); 1558 1559 } 1560} 1561 1562 1563btx=analogRead(JoyStick_X); 1564controlbluetooth(); 1565if(btx<400){ break;} 1566 1567 1568 1569 1570 1571} 1572touslesservosacetangle(90,20); 1573} 1574 //******************************************************************************************************************************* 1575 //******************************************************************************************************************************* 1576 //******************************************************************************************************************************* 1577 1578 1579void PulseLowEnabledPin(int PinNumber, int DurationMicroSecs) 1580{ 1581 // For Low Enabled Pins , 0 = on and 1 = off 1582 digitalWrite(PinNumber, LOW); // Sets the pin on- 1583 delayMicroseconds(DurationMicroSecs); // Pauses for DurationMicroSecs microseconds 1584 1585 digitalWrite(PinNumber, HIGH); // Sets the pin off 1586 delayMicroseconds(DurationMicroSecs); // Pauses for DurationMicroSecs microseconds 1587} 1588 1589void PulsePin(int PinNumber, int DurationMicroSecs) 1590{ 1591 digitalWrite(PinNumber, HIGH); // Sets the pin on 1592 delayMicroseconds(DurationMicroSecs); // Pauses for DurationMicroSecs microseconds 1593 1594 digitalWrite(PinNumber, LOW); // Sets the pin off 1595 delayMicroseconds(DurationMicroSecs); // Pauses for DurationMicroSecs microseconds 1596} 1597 1598String ParseI2CResult(int result) 1599{ 1600 String sresult = ""; 1601 switch(result)// mis en commentaire pour gagner de la place en mmoire 1602 { 1603 case 0: 1604 sresult = "I2C Operation OK ..."; 1605 break; 1606 1607 case I2C_ERROR_WRITING_START_ADDRESS: 1608 sresult = "I2C_ERROR_WRITING_START_ADDRESS"; 1609 break; 1610 1611 case I2C_ERROR_WRITING_DATA: 1612 sresult = "I2C_ERROR_WRITING_DATA"; 1613 break; 1614 1615 case DATA_TOO_LONG: 1616 sresult = "DATA_TOO_LONG"; 1617 break; 1618 1619 case NACK_ON_TRANSMIT_OF_ADDRESS: 1620 sresult = "NACK_ON_TRANSMIT_OF_ADDRESS"; 1621 break; 1622 1623 case NACK_ON_TRANSMIT_OF_DATA: 1624 sresult = "NACK_ON_TRANSMIT_OF_DATA"; 1625 break; 1626 1627 case OTHER_ERROR: 1628 sresult = "OTHER_ERROR"; 1629 break; 1630 1631 default: 1632 sresult = "I2C ERROR TYPE NOT FOUND..."; 1633 break; 1634 } 1635 1636 return sresult; 1637} 1638 1639// --------------------------------------------------------------------------------------------------------------- 1640 1641// Parameters: 1642// start : Start address, use a define for the register 1643// pData : A pointer to the data to write. 1644// size : The number of bytes to write. 1645// 1646int OV7670Write(int start, const byte *pData, int size) 1647{ 1648 int n, error; 1649 1650 Wire.beginTransmission(OV7670_I2C_ADDRESS); 1651 n = Wire.write(start); // write the start address 1652 if (n != 1) 1653 { 1654 return (I2C_ERROR_WRITING_START_ADDRESS); 1655 } 1656 1657 n = Wire.write(pData, size); // write data bytes 1658 if (n != size) 1659 { 1660 return (I2C_ERROR_WRITING_DATA); 1661 } 1662 1663 error = Wire.endTransmission(true); // release the I2C-bus 1664 if (error != 0) 1665 { 1666 return (error); 1667 } 1668 1669 return 0; // return : no error 1670} 1671 1672 1673//// --------------------------------------------------------------------------------------------------------------- 1674// A function to write a single register 1675// 1676int OV7670WriteReg(int reg, byte data) 1677{ 1678 int error; 1679 1680 error = OV7670Write(reg, &data, 1); 1681 1682 return (error); 1683} 1684 1685//// --------------------------------------------------------------------------------------------------------------- 1686// This is a common function to read multiple bytes 1687// from an I2C device. 1688// 1689// It uses the boolean parameter for Wire.endTransMission() 1690// to be able to hold or release the I2C-bus. 1691// This is implemented in Arduino 1.0.1. 1692// 1693int OV7670Read(int start, byte *buffer, int size) 1694{ 1695 int i, n, error; 1696 1697 Wire.beginTransmission(OV7670_I2C_ADDRESS); 1698 n = Wire.write(start); 1699 if (n != 1) 1700 { 1701 return (I2C_READ_START_ADDRESS_ERROR); 1702 } 1703 1704 n = Wire.endTransmission(false); // hold the I2C-bus 1705 if (n != 0) 1706 { 1707 return (n); 1708 } 1709 1710 // Third parameter is true: relase I2C-bus after data is read. 1711 Wire.requestFrom(OV7670_I2C_ADDRESS, size, true); 1712 i = 0; 1713 while(Wire.available() && i<size) 1714 { 1715 buffer[i++] = Wire.read(); 1716 } 1717 if ( i != size) 1718 { 1719 return (I2C_READ_DATA_SIZE_MISMATCH_ERROR); 1720 } 1721 1722 return (0); // return no error 1723} 1724////////////////////////////////// 1725byte ReadRegisterValue(byte RegisterAddress) 1726{ 1727 byte data = 0; 1728 int result; 1729 1730 Wire.beginTransmission(OV7670_I2C_ADDRESS); 1731 result = Wire.write(RegisterAddress); 1732 if(result != 1){Serial.println("Result of write to camera register is: "); Serial.print((int)result,HEX); Serial.println();} 1733 Wire.endTransmission(); 1734 Wire.requestFrom(OV7670_I2C_ADDRESS, 1); 1735 while(Wire.available() < 1); // delay for data 1736 data = Wire.read(); 1737 1738 return data; 1739} 1740 1741//// --------------------------------------------------------------------------------------------------------------- 1742// A function to read a single register 1743// 1744int OV7670ReadReg(int reg, byte *data) 1745{ 1746 int error; 1747 1748 error = OV7670Read(reg, data, 1); 1749 1750 return (error); 1751} 1752 1753// --------------------------------------------------------------------------------------------------------------- 1754int setReg(int reg,byte val){ // set bit(s) in register without changing other bit values 1755 int result; 1756 byte temp; 1757 String reg_n; 1758 temp = ReadRegisterValue(reg); 1759 temp |= val; 1760 result = OV7670WriteReg(reg,temp); 1761 if(result) 1762 { 1763 // find the register text value 1764// reg_n = getRegName(reg); 1765// reg_n += ": "; 1766// DisplayError(reg_n,result); 1767 } 1768 return result; 1769} 1770// --------------------------------------------------------------------------------------------------------------- 1771int clearReg(int reg,byte val){ // clear bit(s) in register without changing other bit values 1772 int result; 1773 byte temp; 1774 String reg_n; 1775 temp = ReadRegisterValue(reg); 1776 temp = temp & ~val; 1777 result = OV7670WriteReg(reg,temp); 1778 if(result) 1779 { 1780 // find the register text value 1781// reg_n = getRegName(reg); 1782// reg_n += ": "; 1783// DisplayError(reg_n,result); 1784 } 1785 return result; 1786} 1787 1788 1789 1790//******************************************************************************************************************************* 1791//******************************************************************************************************************************* 1792//*******************************************************************************************************************************//******************************************************************************************************************************* 1793//******************************************************************************************************************************* 1794//******************************************************************************************************************************* 1795void setup() 1796{ 1797 1798 1799 1800 1801 1802 // Initialize Serial 1803 1804 Serial2.begin(9600); //Tx2 and Rx2 //Connected to Bluetooth Module HC-05 (Bluetooth 2.0) 1805 Serial.begin(115200);// on ne peut pas aller plus vite pour recvoir des imput de processing 1806maestroSerial.begin(200000);// on ne peut aller plus vite que 200000 1807 1808 1809 1810 Serial.println(F("Arduino SERIAL_MONITOR_CONTROLLED CAMERA ... Using ov7670 Camera")); 1811 Serial.println(); 1812 // Setup the OV7670 Camera for use in taking still photos 1813 Wire.begin(); 1814Serial.println(F("----------------------------- Camera Registers ----------------------------")); 1815 ResetCameraRegisters(); 1816 ReadRegisters(); 1817 Serial.println(F("---------------------------------------------------------------------------")); 1818 SetupCamera(); 1819 Serial.println(F("FINISHED INITIALIZING CAMERA ...")); 1820 Serial.println(); 1821 Serial.println(); 1822 1823 1824lcd.begin(16, 2); // set up the LCD's number of columns and rows: 1825 1826 1827 // Initialize SD Card 1828Serial.print(F("\ 1829Initializing SD card...")); 1830 pinMode(HardwareSSPin, OUTPUT); // change this to 53 on a mega 1831 1832 if (!SD.begin(chipSelect)) 1833 { 1834 Serial.println(F("Initialization failed ... /nThings to check:")); 1835 Serial.println(F("- Is a card is inserted?")); 1836 Serial.println(F("- Is your wiring correct?")); 1837 Serial.println(F("- Did you change the chipSelect pin to match your shield or module?")); 1838lcdaffiche("carte SD pas OK", "carte SD pas OK"); 1839 delay(2000); 1840 } else { 1841 Serial.println(F("Wiring is correct and a card is present ...")); 1842 lcdaffiche("carte SD OK", "carte SD OK"); 1843 delay(200); 1844 } 1845 //Fin de Initialize SD Card 1846 1847 1848 1849 1850 pinMode(JoyStick_Z, INPUT_PULLUP); //Z axis is defined as an input PS2 1851 1852 for(byte ii=0;ii<24;ii++){ 1853 for(byte jj=0;jj<24;jj++){ 1854 angleetalon90[(ii)][jj]=90; 1855// angleetalonmax[(ii)][jj]=50; 1856}} 1857 1858 1859 1860 1861 1862lecturecartesd("tab90.txt", angleetalon90);// environ 158 miliseconds pour lire et charger le tableau 1863delay(1000); 1864//lecturecartesd("tabmax.txt", angleetalonmax);// environ 158 miliseconds pour lire et charger le tableau 1865 1866firstpicture=true; 1867comptage=0; 1868int u =0; 1869randomSeed(analogRead(3)); 1870 1871 1872 1873touslesservosacetangle(90,10); 1874} 1875//******************************************************************************************************************************* 1876//******************************************************************************************************************************* 1877//*******************************************************************************************************************************//******************************************************************************************************************************* 1878//******************************************************************************************************************************* 1879//******************************************************************************************************************************* 1880 1881void ExecuteCommand(String Command) 1882{ 1883 1884 if (Command == "QQVGA") 1885 { 1886 1887 Resolution = QQVGA; 1888 SetupOV7670ForQQVGAYUV(); //mais en fait les valeurs qui sont l sont celle de qqcif 1889 Serial.println(F("----------------------------- Camera Registers ----------------------------")); 1890 ReadRegisters(); 1891 Serial.println(F("---------------------------------------------------------------------------")); 1892 1893 } 1894 1895 1896 OV7670WriteReg(0x15, 0x02); 1897 // Delay for registers to settle 1898 delay(100); 1899 1900 // Take Photo 1901 1902 1903 TakePhoto(); 1904} 1905 1906 1907boolean ProcessRawCommandElement(String Element) 1908{ 1909 boolean result = false; 1910 1911 Element.toLowerCase(); 1912 1913 if ((Element == "vga") || 1914 (Element == "vgap") || 1915 (Element == "qvga")|| 1916 (Element == "qqvga")) 1917 { 1918 Element.toUpperCase(); 1919 Command = Element; 1920 result = true; 1921 } 1922 else 1923 if (Element == "thirtyfps") 1924 { 1925 FPSParam = "ThirtyFPS"; 1926 result = true; 1927 } 1928 else 1929 if (Element == "nightmode") 1930 { 1931 FPSParam = "NightMode"; 1932 result = true; 1933 } 1934 else 1935 if (Element == "sawb") 1936 { 1937 AWBParam = "SAWB"; 1938 result = true; 1939 } 1940 else 1941 if (Element == "aawb") 1942 { 1943 AWBParam = "AAWB"; 1944 result = true; 1945 } 1946 else 1947 if (Element == "aveaec") 1948 { 1949 AECParam = "AveAEC"; 1950 result = true; 1951 } 1952 else 1953 if (Element == "histaec") 1954 { 1955 AECParam = "HistAEC"; 1956 result = true; 1957 } 1958 else 1959 if (Element == "yuvmatrixon") 1960 { 1961 YUVMatrixParam = "YUVMatrixOn"; 1962 result = true; 1963 } 1964 else 1965 if (Element == "yuvmatrixoff") 1966 { 1967 YUVMatrixParam = "YUVMatrixOff"; 1968 result = true; 1969 } 1970 else 1971 if (Element == "denoiseyes") 1972 { 1973 DenoiseParam = "DenoiseYes"; 1974 result = true; 1975 } 1976 else 1977 if (Element == "denoiseno") 1978 { 1979 DenoiseParam = "DenoiseNo"; 1980 result = true; 1981 } 1982 else 1983 if (Element == "edgeyes") 1984 { 1985 EdgeParam = "EdgeYes"; 1986 result = true; 1987 } 1988 else 1989 if (Element == "edgeno") 1990 { 1991 EdgeParam = "EdgeNo"; 1992 result = true; 1993 } 1994 else 1995 if (Element == "ablcon") 1996 { 1997 ABLCParam = "AblcON"; 1998 result = true; 1999 } 2000 else 2001 if (Element == "ablcoff") 2002 { 2003 ABLCParam = "AblcOFF"; 2004 result = true; 2005 } 2006 2007 return result; 2008} 2009 2010void ParseRawCommand(String RawCommandLine) 2011{ 2012 String Entries[10]; 2013 boolean success = false; 2014 2015 // Parse into command and parameters 2016 int NumberElements = ParseCommand(RawCommandLine.c_str(), ' ', Entries); 2017 2018 for (int i = 0 ; i < NumberElements; i++) 2019 { 2020 boolean success = ProcessRawCommandElement(Entries[i]); 2021 if (!success) 2022 { 2023 Serial.print(F("Invalid Command or Parameter: ")); 2024 Serial.println(Entries[i]); 2025 } 2026 else 2027 { 2028 Serial.print(F("Command or parameter ")); 2029 Serial.print(Entries[i]); 2030 Serial.println(F(" sucessfully set ...")); 2031 } 2032 } 2033 2034 2035 // Assume parameter change since user is setting parameters on command line manually 2036 // Tells the camera to re-initialize and set up camera according to new parameters 2037 Resolution = None; // Reset and reload registers 2038 ResetCameraRegisters(); 2039 2040} 2041 2042 2043void DisplayHelpCommandsParams() 2044{ 2045 Serial.println(F("....... Help Menu Camera Commands/Params ..........")); 2046 2047 Serial.println(F("Resolution Change Commands: VGA,VGAP,QVGA,QQVGA")); 2048 Serial.println(F("FPS Parameters: ThirtyFPS, NightMode")); 2049 Serial.println(F("AWB Parameters: SAWB, AAWB")); 2050 Serial.println(F("AEC Parameters: AveAEC, HistAEC")); 2051 Serial.println(F("YUV Matrix Parameters: YUVMatrixOn, YUVMatrixOff")); 2052 Serial.println(F("Denoise Parameters: DenoiseYes, DenoiseNo")); 2053 Serial.println(F("Edge Enchancement: EdgeYes, EdgeNo")); 2054 Serial.println(F("Android Storage Parameters: StoreYes, StoreNo")); 2055 Serial.println(F("Automatic Black Level Calibration: AblcON, AblcOFF")); 2056 Serial.println(); 2057 Serial.println(); 2058} 2059 2060void DisplayHelpMenu() 2061{ 2062 Serial.println(F("................. Help Menu ..................")); 2063 Serial.println(F("d - Display Current Camera Command")); 2064 Serial.println(F("t - Take Photograph using current Command and Parameters")); 2065 Serial.println(F("testread - Tests reading files from the SDCard by reading and printig the contents of test.txt")); 2066 Serial.println(F("testwrite - Tests writing files to SDCard")); 2067 2068 //Serial.println(F("sdinfo - Display SD Card information including files present")); 2069 Serial.println(F("help camera - Displays Camera's Commands and Parameters")); 2070 Serial.println(); 2071 Serial.println(); 2072 2073} 2074 2075void DisplayCurrentCommand() 2076{ 2077 // Print out Command and Parameters 2078 Serial.println(F("Current Command:")); 2079 Serial.print(F("Command: ")); 2080 Serial.println(Command); 2081 2082 Serial.print(F("FPSParam: ")); 2083 Serial.println(FPSParam); 2084 2085 Serial.print(F("AWBParam: ")); 2086 Serial.println(AWBParam); 2087 2088 Serial.print(F("AECParam: ")); 2089 Serial.println(AECParam); 2090 2091 Serial.print(F("YUVMatrixParam: ")); 2092 Serial.println(YUVMatrixParam); 2093 2094 Serial.print(F("DenoiseParam: ")); 2095 Serial.println(DenoiseParam); 2096 2097 Serial.print(F("EdgeParam: ")); 2098 Serial.println(EdgeParam); 2099 2100 Serial.print(F("ABLCParam: ")); 2101 Serial.println(ABLCParam); 2102 2103 Serial.println(); 2104} 2105//******************************************************************************************************************************* 2106//******************************************************************************************************************************* 2107//*******************************************************************************************************************************//******************************************************************************************************************************* 2108//******************************************************************************************************************************* 2109//******************************************************************************************************************************* 2110//****************************************** LOOP *********************************************************** 2111 2112void loop() 2113{ 2114 2115 2116btx=analogRead(JoyStick_X); 2117 bty=analogRead(JoyStick_Y); 2118 btz=digitalRead(JoyStick_Z); 2119 delay(200); 2120controlbluetooth(); 2121 2122if(bty<400){nomenualain=nomenualain-1;}// joystick bas 2123if(bty>800){nomenualain=nomenualain+1;}// joystick haut 2124if(nomenualain>12){nomenualain=12;} 2125if(nomenualain<0){nomenualain=0;} 2126 2127 2128 2129 2130 2131 if(nomenualain==0){lcdaffiche("menu","^v");} 2132 if(nomenualain==1){lcdaffiche("reglage du 90","->");} 2133 if(nomenualain==2){lcdaffiche("sinusoide","->");} 2134 if(nomenualain==3){lcdaffiche("camera","->");} 2135 if(nomenualain==4){lcdaffiche("dessin","->");} 2136 if(nomenualain==5){lcdaffiche("input","->");} 2137 if(nomenualain==6){lcdaffiche("tous a 90","->");} 2138if(nomenualain==7){lcdaffiche("tous au maximum de","brillance ->");} 2139if(nomenualain==8){lcdaffiche("reglage du max de","brillance ->");} 2140if(nomenualain==9){lcdaffiche("balle","->");} 2141if(nomenualain==10){lcdaffiche("pixel","->");} 2142if(nomenualain==12){lcdaffiche("camera macro","->");} 2143 2144 2145if(btx>800)//fleche droite 2146{ 2147if(nomenualain==1){menu1reglagedu90();} 2148 if(nomenualain==2){ mouvementsinusoidal();} 2149if(nomenualain==3){macro=false;ExecuteCommand("QQVGA");} 2150if(nomenualain==4){ dessin();} 2151if(nomenualain==5){ input();} 2152if(nomenualain==6){touslesservosacettevaleur(90);} 2153if(nomenualain==7){touslesservosaumaxbrillance();} 2154if(nomenualain==8){menu8reglagebrillance();} 2155if(nomenualain==9){balle();} 2156if(nomenualain==10){lirepixel();} 2157if(nomenualain==11){trimagedu90();} 2158if(nomenualain==12){macro=true;nomenualain=3;ExecuteCommand("QQVGA");} 2159 2160} 2161 2162 2163 2164} 2165 2166 2167 2168//******************************************************************************************************************************* 2169//******************************************************************************************************************************* 2170//*******************************************************************************************************************************//******************************************************************************************************************************* 2171//******************************************************************************************************************************* 2172//*******************************************************************************************************************************//******************************************************************************************************************************* 2173//******************************************************************************************************************************* 2174//*******************************************************************************************************************************//******************************************************************************************************************************* 2175//******************************************************************************************************************************* 2176//*******************************************************************************************************************************//******************************************************************************************************************************* 2177//******************************************************************************************************************************* 2178//******************************************************************************************************************************* 2179int ParseCommand(const char* commandline, char splitcharacter, String* Result) 2180{ 2181 int ResultIndex = 0; 2182 int length = strlen(commandline); 2183 String temp = ""; 2184 2185 for (int i = 0; i < length ; i++) 2186 { 2187 char tempchar = commandline[i]; 2188 if (tempchar == splitcharacter) 2189 { 2190 Result[ResultIndex] += temp; 2191 ResultIndex++; 2192 temp = ""; 2193 } 2194 else 2195 { 2196 temp += tempchar; 2197 } 2198 } 2199 2200 // Put in end part of string 2201 Result[ResultIndex] = temp; 2202 2203 return (ResultIndex + 1); 2204} 2205 2206 2207//********************************************************************************* 2208//**********************affichage sur LCD*********************************** 2209//*************************************************************************** 2210//*************************************************************************** 2211// affichage LCD pin lcd(4, 6, 10, 11, 12, 13); 2212//*************************************************************************** 2213 void lcdaffiche( String nom1,String nom2)//en parametre les deux ligne afficher 2214 { 2215 2216char array1[]=" "; 2217nom1.toCharArray(array1,17);//la string reue en parametre tranforme en tableau qui sera lu caractere aprs caractere 2218char array2[]=" "; 2219nom2.toCharArray(array2,17);//la string reue en parametre tranforme en tableau qui sera lu caractere aprs caractere 2220 2221 2222 lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner 2223 2224lcd.setCursor(0,0); //1re ligne // set the cursor to column 15, line 0 2225 for (int pos = 0; pos < nom1.length(); pos++) 2226 { 2227 lcd.print(array1[pos]); // Print a message to the LCD. 2228 2229} 2230 lcd.setCursor(0,1); //1re ligne // set the cursor to column 15, line 0 2231 for (int pos = 0; pos < nom2.length(); pos++) 2232 { 2233 lcd.print(array2[pos]); // Print a message to the LCD. 2234} 2235 2236 2237 //delay(100); 2238 } 2239 2240 2241 2242 2243//*********************************************************************************** 2244//*********************************************************************************** 2245//**** Input du programme processing connect en usb sur arduino ****************** 2246//*********************************************************************************** 2247 2248void input(){ 2249 while(nomenualain==5){ 2250 //lcdaffiche(messageFromPC,String(integer3FromPC)); 2251//lcdaffiche("input","OK,"+String(integer1FromPC)+","+String(integer2FromPC)+","+String(integer3FromPC)); 2252//delay(1000);// ne pas mettre de delay sinon a bloque l'entre des datas de processing 2253 recvWithStartEndMarkers(); 2254 if (newData == true) { 2255 strcpy(tempChars, receivedChars); 2256 // this temporary copy is necessary to protect the original data 2257 // because strtok() used in parseData() replaces the commas with \\0 2258 //parseData(); 2259 //showParsedData(); 2260 newData = false; 2261 } 2262 2263 btx=analogRead(JoyStick_X); 2264 //delay(50); 2265 if(btx<400){ 2266break;} 2267 } 2268 touslesservosacetangle(90,30); 2269} 2270 2271 2272//*********************************************************************************** 2273//**************sous routine de imput ************************************************* 2274void recvWithStartEndMarkers() { 2275 static boolean recvInProgress = false; 2276 static byte ndx = 0; 2277 char startMarker = '<'; 2278 char endMarker = '>'; 2279 char rc; 2280 2281 while (Serial.available() > 0 && newData == false) { 2282 rc = Serial.read(); 2283 2284 if (recvInProgress == true) { 2285 if (rc != endMarker) { 2286 receivedChars[ndx] = rc; 2287 ndx++; 2288 if (ndx >= numChars) { 2289 ndx = numChars - 1; 2290 } 2291 } 2292 else { 2293 receivedChars[ndx] = '\\0'; // terminate the string 2294 recvInProgress = false; 2295 ndx = 0; 2296 parseData(); 2297 showParsedData(); 2298 //delay(20);// pour attendre que les servos se soient dplacs 2299 //Serial.println("OK,"+String(integer1FromPC)+","+String(integer2FromPC)+","+String(integer3FromPC));// envoie un reu processing 2300 Serial.println(String(integer1FromPC)+","+String(integer2FromPC)+","+String(integer3FromPC));// envoie un reu processing 2301 newData = true; 2302 } 2303 } 2304 2305 else if (rc == startMarker) { 2306 recvInProgress = true; 2307 } 2308 } 2309} 2310 2311//*********************************************************************************** 2312//**************sous routine de imput ************************************************* 2313void parseData() { // split the data into its parts 2314 2315 2316 char * strtokIndx; // this is used by strtok() as an index 2317 2318 strtokIndx = strtok(tempChars,","); // get the first part - the string 2319 strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC 2320 2321// strtokIndx = strtok(NULL, ","); // this continues where the previous call left off 2322// integer0FromPC = atoi(strtokIndx); // convert this part to an integer 2323//lcdaffiche(messageFromPC,""); 2324//delay(100); 2325 2326 strtokIndx = strtok(NULL, ","); // this continues where the previous call left off 2327 integer1FromPC = atoi(strtokIndx); // convert this part to an integer 2328 2329 strtokIndx = strtok(NULL, ","); 2330 integer2FromPC = atoi(strtokIndx); 2331 2332 strtokIndx = strtok(NULL, ","); 2333 integer3FromPC = atoi(strtokIndx); 2334 2335} 2336 2337//============ 2338 2339//*********************************************************************************** 2340//**************sous routine de imput ************************************************* 2341// bouge les servos en fonctions des ordres envoys par processing 2342void showParsedData() { 2343 2344//lcdaffiche(messageFromPC,String(integer3FromPC)); 2345//if(strcmp(messageFromPC,"brillance")==0){// la comparaison d'une string avec un tableau de char 2346//lcdaffiche(messageFromPC,String(integer3FromPC)); 2347//delay(2000); 2348 2349 2350bougeservo(integer2FromPC, integer1FromPC,integer3FromPC,30, 0); 2351} 2352 2353 2354//********************************************************************************* 2355//******************** Lecture carte SD ******************************* 2356//********************************************************************************* 2357//*************************************************************************** 2358//The circuit: 2359// * SD card attached to SPI bus as follows: avec une carte sd neuve de 2Go format en Fat 2360// ** MOSI - pin 51 on Arduino Uno/Duemilanove/Diecimila 2361// ** MISO - pin 50 on Arduino Uno/Duemilanove/Diecimila 2362// ** SCK - pin 52 clock on Arduino Uno/Duemilanove/Diecimila 2363// ** CS - pin53 2364//** le GND sur le GND d'arduino 2365//* le 5v VCCsur le 5 v de la'rduino: Attention ne pas utiliser le3,3V 2366//******* si a ne fonctionne pas penser changer a carte SD est souvent la cause 2367// on a un fichier par prochaine valeur donner 2368 2369//*************************************************************************** 2370 int lecturecartesd( String nom, byte tableau[24][24])//en 1er parametre le nom du fichier ouvrir, en deuxime le tableau qui sera rempli par les valeurs du fichier de la carte SD, entre chaque nombre il y a un ; qui dlimite chaque servo 2371 { 2372 //Attention le nom ne doit pas avoir plus de 8 caractres 2373 int duree=50; 2374char c;// variable du carractere lu par READ(); 2375int li=0; // ligne =le numro du servo 2376int col=0;// colonne = prochaine valeur pour le m'eme servo ou a peuttre aussi le numero de la carte 16 servo channel 2377String lenombre=""; 2378 2379int xx; 2380int yy; 2381 myFile = SD.open(nom); 2382 2383//lcdaffiche(nom,String(myFile.size())); 2384//delay (2000); 2385 2386 if (myFile) { 2387 2388 2389for (long jj = 0; jj< myFile.size(); jj++) // boucle de parcours du fichier 2390{ 2391char c = myFile.read(); // lecture du carracter suivant 2392 2393//*********** 2394switch (c){ 2395 //*********** 2396 case ';':// entre chaque nombre il y a un ; qui dlimite chaque servo 2397 2398 if(li>23){duree=lenombre.toInt();}// le dernier nombre est la dure d'execution entre chaque fichier 2399 else{ 2400 2401tableau[li][col]=lenombre.toInt(); 2402//Serial.println(col); 2403//Serial.println(li); 2404//Serial.print(String(angle[li][col])+";"); 2405//Serial.print("tableau "); 2406//Serial.println(sizeof(angle[0])/2) 2407 } 2408col=col+1; 2409lenombre=""; 2410 break; 2411 2412 //*********** 2413 case 'X':// il ya un X la fin de chaque ligne 2414//Serial.println("on passe a une autre ligne"); 2415li=li+1; 2416 col=0; 2417 break; 2418 2419 //*********** 2420 default: 2421 lenombre=lenombre+c; 2422 } 2423 } 2424myFile.close(); 2425 } 2426 2427 2428 2429 return int(duree); 2430} 2431//********************************************************************************* 2432//********************************************************************************* 2433//************************* Ecriture carte SD ****************************** 2434//********************************************************************************* 2435//********************************************************************************* 2436 void ecriturecartesd( String nom, byte tableau[24][24])//en 1er parametre le nom du fichier ouvrir, en deuxime le tableau qui sera rempli par les valeurs du fichier dans la carte SD 2437 2438{ 2439 //Attention le nom ne doit pas avoir plus de 8 caractres 2440 2441 2442// if (SD.exists(nom)) { 2443// Serial.println(" exists."); 2444// } else { 2445// Serial.println(" doesn't exist."); 2446// } 2447//// open a new file and immediately close it: 2448// Serial.println("Creating"); 2449// myFile = SD.open(nom, FILE_WRITE); 2450// myFile.close(); 2451// 2452// 2453// // Check to see if the file exists: 2454// if (SD.exists(nom)) { 2455// Serial.println(" exists."); 2456// } else { 2457// Serial.println(" doesn't exist."); 2458// } 2459 2460 // delete the file: 2461 // Serial.println("Removing example.txt..."); 2462 SD.remove(nom); 2463 delay(1000); 2464 2465// if (SD.exists(nom)) { 2466// delay(1000); 2467// Serial.println("example.txt exists."); 2468// } else { 2469// delay(1000); 2470// Serial.println("example.txt doesn't exist."); 2471// } 2472 2473 myFile = SD.open(nom, FILE_WRITE); 2474 delay(1000); 2475 Serial.println(myFile); 2476 if (myFile) { 2477 2478for(int i=0;i<24; i++) {// pour toutes les lignes de servos 2479for( int j=0;j<24;j++) {// pour toutes les colonnes de servos 2480 myFile.print(String(tableau[i][j])+";"); 2481 myFile.flush(); 2482 delay(20); 2483} 2484myFile.println("X"); 2485 myFile.flush(); 2486 delay(20); 2487 2488 } 2489myFile.close(); 2490 } 2491 2492 Serial.println("c'est ecrit"); 2493 2494 } 2495//********************************************************************************************* 2496// **********menu** 1 ********************** 2497 void menu1reglagedu90(){ 2498 2499touslesservosacetangle(90,30); 2500 2501 while(nomenualain==1){ 2502 2503 lcdaffiche("X="+String(colonne),"Y="+String(ligne)); 2504 btx=analogRead(JoyStick_X); 2505 bty=analogRead(JoyStick_Y); 2506 //lcdaffiche(String(btx),String(bty)); 2507 delay(50); 2508 2509if(btx<400){ 2510if(colonne>0){ 2511 colonne=colonne-1;}} 2512 2513if(btx>800){ 2514if(colonne<23){ 2515 colonne=colonne+1;}} 2516 2517if(bty>800){ 2518if(ligne>0){ 2519 ligne=ligne-1;}} 2520 2521if(bty<400){ 2522if(ligne<23){ 2523 ligne=ligne+1;}} 2524 2525 2526 2527 2528if((colonne!=colonneavant)or(ligne!=ligneavant)){ 2529 2530 2531bougeservo(colonne, ligne,degremin,0, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2532delay(300); 2533 2534bougeservo(colonne, ligne,degremax,0, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2535delay(300); 2536 2537 2538bougeservo(colonne, ligne,angleetalon90[ligne][colonne],0, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2539 2540 2541colonneavant=colonne; 2542ligneavant=ligne;} 2543 2544 btz=digitalRead(JoyStick_Z); 2545 2546if(btz==0){delay(300); 2547btz=digitalRead(JoyStick_Z); 2548 delay(100); 2549if(btz==0){nomenualain=2;}// on a pes longtemps sur le bouton ce qui fait qu'on revient en arrire 2550else{// on a pas pes longtemps sur le bouton 2551 2552 nomenualain=11; 2553 } 2554 } 2555 2556} 2557} 2558 //********************************************************************************************* 2559// **********menu** 11 ********************** 2560void trimagedu90(){ 2561 2562 while(nomenualain==11){ 2563lcdaffiche("reglage du 90","X="+String(colonne)+"Y="+String(ligne)+" :"+String( angleetalon90[ligne][colonne])); 2564 2565// bty=analogRead(JoyStick_Y); 2566// delay(100); 2567//if(bty>800){ angleetalon90[ligne][colonne]= angleetalon90[ligne][colonne]+1;} 2568//if(bty<400){ angleetalon90[ligne][colonne]= angleetalon90[ligne][colonne]-1;} 2569 2570btpot=analogRead(potentiometre); 2571valeur=map(btpot, 0, 1023, degremin, degremax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2572angleetalon90[ligne][colonne]=valeur; 2573 2574bougeservo(colonne, ligne,angleetalon90[ligne][colonne],10,0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2575 2576 2577 btx=analogRead(JoyStick_X); 2578 delay(50); 2579 if(btx<400){ 2580 nomenualain=1; 2581 menu1reglagedu90();} 2582 2583 if(btx>800){lcdaffiche("write on SD","un moment svp"); 2584 delay(1000); 2585 ecriturecartesd("tab90.txt",angleetalon90); 2586 lcdaffiche("OK finish",""); 2587 delay(1000); 2588 2589 nomenualain=1;} 2590 menu1reglagedu90(); } 2591} 2592 2593//********************************************************************************************* 2594// **********menu** 8 ********************** 2595 void menu8reglagebrillance(){ 2596 2597for(int y=0;y<24;y++){ // pour tousles mettre 90 selon l'angle etalon 2598 for(int x=0;x<24;x++){ 2599// valeur=angleetalonmax[y][x];// pour finir le milieu est 110 degrs 2600 valeur=constrain(valeur, degremin, degremax); 2601valeur=map(valeur, 0, 180, valeurmin, valeurmax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2602//bougeservo(x, y,valeur,10, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2603}} 2604 2605 while(nomenualain==8){ 2606 2607 lcdaffiche("X="+String(colonne),"Y="+String(ligne)); 2608 btx=analogRead(JoyStick_X); 2609 bty=analogRead(JoyStick_Y); 2610 2611 delay(100); 2612 2613if(btx<400){ 2614if(colonne>0){ 2615 colonne=colonne-1;}} 2616 2617if(btx>800){ 2618if(colonne<23){ 2619 colonne=colonne+1;}} 2620 2621if(bty<400){ 2622if(ligne>0){ 2623 ligne=ligne-1;}} 2624 2625if(bty>800){ 2626if(ligne<23){ 2627 ligne=ligne+1;}} 2628 2629 2630 2631 2632if((colonne!=colonneavant)|(ligne!=ligneavant)){ 2633 2634 2635bougeservo(colonne,ligne,degremin,10,0); ////moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2636delay(300); 2637 2638 2639bougeservo(colonne, ligne,degremax,10, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2640delay(300); 2641 2642// valeur= angleetalonmax[ligne][colonne]; 2643 2644//bougeservo(colonne, ligne,valeur,10, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2645 2646 2647 2648colonneavant=colonne; 2649ligneavant=ligne;} 2650 2651 btx=analogRead(JoyStick_X); 2652 2653 if(btx<400){delay(500); 2654 btx=analogRead(JoyStick_X);; 2655 delay(500); 2656 2657 if(btx<400){nomenualain=2;}// on a pes longtemps sur le bouton ce qui fait qu'on revient en arrire 2658else{// on a pas pes longtemps sur le bouton 2659 2660 nomenualain=10; 2661 } 2662 } 2663 2664} 2665} 2666 2667// **********menu** 10 ********************** 2668void trimagedumax(){ 2669 2670 while(nomenualain==10){ 2671//lcdaffiche("reglage du 90","X="+String(colonne)+"Y="+String(ligne)+" :"+String( angleetalonmax[ligne][colonne])); 2672 2673// bty=analogRead(JoyStick_Y); 2674// delay(100); 2675//if(bty>800){ angleetalon90[ligne][colonne]= angleetalon90[ligne][colonne]+1;} 2676//if(bty<400){ angleetalon90[ligne][colonne]= angleetalon90[ligne][colonne]-1;} 2677 2678btpot=analogRead(potentiometre); 2679valeur=map(btpot, 0, 1023, degremin, degremax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2680//angleetalonmax[ligne][colonne]=valeur; 2681//valeur=constrain( angleetalonmax[ligne][colonne], degremin, degremax); 2682valeur=map(valeur, 0, 180, valeurmin, valeurmax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2683 2684//bougeservo(colonne,ligne,valeur,10, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2685 2686 2687 btx=analogRead(JoyStick_X); 2688 delay(50); 2689 if(btx<400){ 2690 nomenualain=8; 2691 menu8reglagebrillance();} 2692 2693 if(btx>800){lcdaffiche("ecriture sur carte SD","un moment svp"); 2694 delay(1000); 2695// ecriturecartesd("tabmax.txt",angleetalonmax); 2696 lcdaffiche("voil c'est fait",""); 2697 delay(1000); 2698 2699 nomenualain=8; 2700 menu8reglagebrillance();} 2701 } 2702} 2703 2704 2705// **********tous les servos cette valeur ********************** 2706void touslesservosacettevaleur(int angle){ 2707int valeur; 2708 2709 2710for(int y=0;y<24;y++){ 2711 for(int x=0;x<24;x++){ 2712 valeur=90; 2713device[x].setAcceleration(y, 10); 2714 2715}} 2716 2717 2718 while(nomenualain==6){ 2719lcdaffiche("servo a",String(angle)+" degres"); 2720 2721// bty=analogRead(JoyStick_Y); 2722// delay(10); 2723//if(bty>800){angle=angle+10;} 2724//if(bty<400){angle=angle-10;} 2725 2726 btpot=analogRead(potentiometre); 2727 //controlbluetooth(); 2728// Serial.print("pot "); 2729// Serial.print(btpot); 2730 2731 //les valeurs du pot sont transformes en angle de degr min degremax disons de 30 150 degrs 2732 angle=map(btpot, 0, 1023, degremin, degremax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2733 2734 2735 2736for(int y=0;y<24;y++){ 2737 for(int x=0;x<24;x++){ 2738 2739 2740valeur=angle; 2741 valeur=(angle-90)+ angleetalon90[y][x];// 2742valeur=constrain(valeur, degremin, degremax); 2743 2744if(x%2==0){valeur=map(valeur, 0, 180, valeurmin, valeurmax);}//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2745else{ 2746//valeur=map(valeur, 0, 180, valeurmax, valeurmin);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2747valeur=map(valeur, 0, 180, valeurmin, valeurmax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2748} 2749 2750//bougeservo(x, y,valeur,0, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse)// mais c'est trop saccad 2751device[x].setTarget(y, valeur); 2752}} 2753 2754 2755 2756 2757 2758 2759 btx=analogRead(JoyStick_X); 2760controlbluetooth(); 2761 //delay(50); 2762 if(btx<400){ 2763 break;} 2764 2765 2766 } 2767 2768} 2769 2770// **********tous les servos la max de brillance ********************** 2771void touslesservosaumaxbrillance(){ 2772int valeur; 2773 2774 while(nomenualain==7){ 2775lcdaffiche("servo au maximum","de brillance"); 2776for(int y=0;y<24;y++){ 2777 for(int x=0;x<24;x++){ 2778// valeur=constrain(angleetalonmax[y][x], degremin, degremax); 2779valeur=constrain(valeur, degremin, degremax); 2780valeur=map(valeur, 0, 180, valeurmin, valeurmax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2781//bougeservo(x, y,valeur,10, 0);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 2782}} 2783 2784 2785 btx=analogRead(JoyStick_X); 2786 delay(50); 2787 if(btx<400){ 2788 break;} 2789} 2790 } 2791//*********************************** 2792void mouvementsinusoidal() 2793{ 2794 2795lcdaffiche("sinusoide",""); 2796float alpha =0 ;// angle en radian de 0 6.283: angle de consigne pour la commande du servo 2797float beta =0 ;// angle en radian de 0 6.283:angle de consigne pour la commande du servo 2798float alpha0 =0 ;// angle en radian de 0 6.283: angle de consigne audpart qui sera augment de iota chaque cycle de j 2799float beta0 =3.14 ;//pi/2 90 degrs angle en radian de 0 6.283:angle de consigne audpart qui sera augment de iota chaque cycle de j 2800float gamma =0.4;// angle en radian de 0 6.283: valeur de dcalage des alpha 2801float teta =0.2 ;//0.2 avant angle en radian de 0 6.283: valeur de dcalage des beta 2802float iota =0.2 ;// angle en radian de 0 6.283: valeur d'incrmenation de tous les servos sur alpha0 2803float zeta =0.1 ;//0.1,puis0.2 angle en radian de 0 6.283: valeur d'incrmenation de tous les servos sur beta0 2804int valeurseuil=-3000; //-10000permet de dclencher le mouvement qu' partir d'une certaine valeur , permet de faire des vagues 2805int valeur=0;// valeur donne au servo va de 150 550, mais sera map pour que a aille a 238-438 env 2806 float randnum; 2807 2808 for(int y=0;y<24;y++){ 2809 for(int x=0;x<24;x++){device[x].setAcceleration(y, 20);}} 2810 2811 2812 while(nomenualain==2){ 2813 2814randnum=random(-10,8); 2815 valeurseuil=(randnum*1000);// peut aller de -10000 +10000, mais ici on va de -5000 +5000 2816 //valeurseuil=-10000; 2817 2818 randnum=random(-3,3); 2819 teta=(randnum/5); 2820 2821 randnum=random(-2,2); 2822iota=(randnum/2); 2823 //iota=2; 2824 2825 randnum=random(-2,2); 2826 zeta=(randnum/2); 2827 if ((zeta==0)&(iota==0)){ 2828 randnum=random(-2,2); 2829 zeta=(randnum/2);} 2830 2831//zeta=2; 2832 2833 2834for(byte t=0;t<40; t++){ 2835lcdaffiche("t:"+String(teta)+" i:"+String(iota),"z:"+String(zeta)+"s:"+String(valeurseuil)); 2836 2837// 2838 for(byte y=0;y<24; y++) {// pour toutes les lignes de servos 2839 2840 for( byte x=0;x<24;x++) {// pour toutes les colonnes de servos 2841 2842valeur=((sin(alpha)/2+cos(beta)/2))*10000; 2843//valeur=((sin(alpha)/3+cos(beta)/3+cos(iota)/3))*10000; 2844 2845if(valeur>valeurseuil){// permet de propager une onde avec un petit arret 2846//valeur=map(valeur,valeurseuil, 10000, degremin, degremax);// les degrs des servo sont entre 25-150(degrmin, degrmax)//pour des mouvements de degremin degremax 2847valeur=map(valeur,valeurseuil, 10000, degremax, 30);//pour des mouvements de 70 a degremax, on map l'envers pour que ce qui bouge soit brillant et pas noir 2848 2849//// pour envoi de la photo sur processing 2850//Serial.print(valeur);// 2851//Serial.print(",");// angle,x,y avec un retour la ligne println('\ 2852' sur processing) 2853//Serial.print(x); 2854//Serial.print(","); 2855//Serial.println(y);// avec retour la ligne qui est detect par processing 2856// fin d' envoi de la photo sur processing 2857// 2858 2859 2860valeur=(valeur-90)+ angleetalon90[y][x];// 2861valeur=constrain(valeur, degremin, degremax);//pour des mouvements de degremin degremax 2862valeur=map(valeur, 0, 180, valeurmin, valeurmax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2863 valeur=constrain(valeur, valeurmin, valeurmax); 2864 2865device[x].setTarget(y, valeur); 2866} 2867 2868alpha=alpha0+x*gamma; 2869 } 2870 beta=beta0+y*teta; 2871 } 2872//delay(300);// si on met acceleration sur 1, a ralenti les servos du coup il faut un dali pour qu'il puisse atteindre la valeur a temps 2873alpha0=alpha0+iota;// permet de dplacer la vagues selon l'axe y 2874beta0=beta0+zeta; // permet de dplacer la vagues selon l'axe x 2875//delay(12); 2876} 2877 2878 btx=analogRead(JoyStick_X); 2879controlbluetooth(); 2880 // delay(50); 2881 if(btx<400){ 2882 break; 2883 } 2884 2885 2886} 2887touslesservosacetangle(90,20); 2888 2889 2890} 2891 2892//********************************************************************** 2893 2894// pour le module HC-08BLE bluetooth 4.0 CC2541 2895// VCC sur 5volt de l'arduino 2896// GND sur GND de l'arduino 2897// RX du blutooth va sur le TX2 de l'arduino 2898// TX du bluetooth var sur le RX2 de l'aeduino 2899// ne pas oublier d'activer le bluetoth sur le telephone 2900 2901void controlbluetooth(){ 2902 byte ndx = 0; 2903 char rc; 2904char messageFromPC[numChars] = {0}; 2905 2906 while (Serial2.available() > 0 && newData == false) { 2907 rc = Serial2.read(); 2908 if (rc != '#') { 2909 receivedChars[ndx] = rc; 2910 ndx++; 2911 if (ndx >= numChars) { 2912 ndx = numChars - 1; 2913 }} 2914else { 2915 2916 receivedChars[ndx] = '\\0'; // terminate the string 2917 ndx = 0; 2918 2919 newData=true; 2920 } 2921} 2922 2923String mes; 2924if (newData == true) { 2925 2926char * strtokIndx; // this is used by strtok() as an index 2927 strcpy(tempChars, receivedChars); 2928 strtokIndx = strtok(tempChars,"="); // strtokIndx = strtok(tempChars,"="); // get the first part - the string 2929 strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC 2930 strtokIndx = strtok(NULL, ""); 2931 integer1FromPC = atoi(strtokIndx); 2932 2933mes=String(messageFromPC); 2934 2935 2936//lcdaffiche(messageFromPC,String(integer1FromPC)); 2937 2938 2939 2940} 2941newData=false; 2942 2943//delay(100); 2944if(mes=="aU"&&integer1FromPC==0){bty=900;} 2945if(mes=="aD"&&integer1FromPC==0){bty=300;} 2946if(mes=="aR"&&integer1FromPC==0){btx=900;} 2947if(mes=="aL"&&integer1FromPC==0){btx=300;} 2948if(mes=="pot"){btpot=integer1FromPC;} 2949 2950 2951} 2952 2953 2954 2955 2956//*********************************** 2957void dessin(){ 2958 2959touslesservosacetangle(90,20); 2960 2961// 2962while(nomenualain==4){ 2963byte vitesse=0; 2964 2965//// onde sinusale 2966//float incr=0; 2967//for(int tours=1;tours<60;tours++){ 2968// 2969// for(int y=0;y<24;y++){ 2970// for(int x=0;x<24;x++){ 2971//if(y>(12+6*sin((x+incr)*0.26))){bougeservo(x,y,70,40,0);} 2972//else{bougeservo(x,y,140,40,0);} 2973// 2974// } 2975// } 2976// incr=incr+0.4; 2977//} 2978 2979 2980 2981 2982//// sinus****************************************************** 2983touslesservosacetangle(90,10); 2984float alpha=0; 2985float beta=0; 2986float t=0; 2987float v=0; 2988byte angulation=0; 2989 2990 t=sin(alpha)*1000; 2991 angulation=map(t, -1000, 1000, degremin+5, degremax-10);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 2992 2993for(int tours=1;tours<60;tours++){ 2994 2995 for(int y=0;y<24;y++){ 2996 for(int x=0;x<24;x++){ 2997 2998bougeservo(x,y,angulation,0,0);// si acceleration =0 bougeservo ne passe pas du tout la passer au servo, si on la passe a ralentit 2999 3000//beta=beta+0.25;// 6.28/24=0.2616// du coup a ne bouge pas chaque avancement de y 3001 3002//t=(sin(alpha)+sin(beta))*500; 3003t=sin(alpha)*1000; 3004angulation=map(t, -1000, 1000, degremin+5, degremax-10);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 3005} 3006 alpha=alpha+0.28;// 6.28/24=0.2616// du coup a ne bouge pas chaque avancement de y 3007 //pour que l'effet soit coul, il ne faut pas dpass 0.28 d'augmentation avec une acceleration 10 et avec setTarget qui va plus 3008 //rapidement que bouge servo 3009 3010} 3011} 3012 3013 3014 btx=analogRead(JoyStick_X); 3015controlbluetooth(); 3016 // delay(50); 3017 if(btx<400){ 3018 break;} 3019 3020 3021 3022 3023// 1 anneaux qui se repete sur fond invers*********************************** 3024touslesservosacetangle(90,20); 3025 3026for(int tours=1;tours<4;tours++){ 3027 3028int x0=random(0,23); 3029int y0=random(0,23); 3030 3031 3032for(int rayon=1;rayon<55;rayon++){ 3033drawCircle(x0,y0,rayon,40,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3034drawCircle(x0,y0,rayon-8,40,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3035drawCircle(x0,y0,rayon-16,40,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3036drawCircle(x0,y0,rayon-24,40,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3037drawCircle(x0,y0,rayon-32,40,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3038delay(150); 3039drawCircle(x0,y0,rayon-1,90,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3040drawCircle(x0,y0,rayon-9,90,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3041drawCircle(x0,y0,rayon-17,90,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3042drawCircle(x0,y0,rayon-25,90,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3043drawCircle(x0,y0,rayon-33,90,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3044} 3045 3046} 3047 btx=analogRead(JoyStick_X); 3048controlbluetooth(); 3049 // delay(50); 3050 if(btx<400){ 3051 break;} 3052 3053 3054 3055 3056 3057// un rond qui rebondit************************* 3058touslesservosacetangle(degremax-10,30); 3059int x0=random(0,23); 3060int y0=0; 3061float incrx=1; 3062float incry=1; 3063float accel=0.45; 3064 3065for(int tours=1;tours<100;tours++){ 3066 3067drawCircle(x0,y0,2,50,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3068drawCircle(x0,y0,3,50,0,vitesse); 3069delay(150); 3070drawCircle(x0,y0,2,degremax-10,0,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3071drawCircle(x0,y0,3,degremax-10,0,vitesse); 3072delay(10); 3073 3074x0=x0+incrx; 3075y0=y0+incry; 3076incry=incry+accel; 3077//lcdaffiche(String(x0)+" "+String(y0), String(incry)); 3078//delay(1000); 3079if(x0>23){incrx=-1;} 3080if(y0>=23){y0=23;incry=incry-1;incry=-incry;} 3081if(x0<0){incrx=1;} 3082//if(y0<0){incry=-incry;} 3083} 3084 btx=analogRead(JoyStick_X); 3085controlbluetooth(); 3086 // delay(50); 3087 if(btx<400){ 3088 3089 break;} 3090// 3091// deux anneaux qui se croisent 3092 3093touslesservosacetangle(degremax-10,20); 3094for(int tours=1;tours<3;tours++){ 3095 3096int x0=random(0,12); 3097int y0=random(0,23); 3098int x1=random(13,23); 3099int y1=random(0,23); 3100 3101for(int rayon=1;rayon<32;rayon++){ 3102drawCircle(x0,y0,rayon,70,10,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3103drawCircle(x1,y1,rayon,70,10,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3104delay(100); 3105drawCircle(x0,y0,rayon-1,degremax-10,10,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3106drawCircle(x1,y1,rayon-1,degremax-10,10,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3107} 3108 3109} 3110 btx=analogRead(JoyStick_X); 3111controlbluetooth(); 3112 // delay(50); 3113 if(btx<400){ 3114 3115 break;} 3116 3117// deux anneaux qui se croisent mais sur fond invers*********************************** 3118touslesservosacetangle(90,10); 3119 3120for(int tours=1;tours<4;tours++){ 3121 3122int x0=random(0,12); 3123int y0=random(0,23); 3124int x1=random(13,23); 3125int y1=random(0,23); 3126 3127for(int rayon=1;rayon<32;rayon++){ 3128drawCircle(x0,y0,rayon,degremin+10,20,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3129drawCircle(x1,y1,rayon,degremin+10,20,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3130delay(100); 3131drawCircle(x0,y0,rayon-1,90,20,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3132drawCircle(x1,y1,rayon-1,90,20,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3133} 3134 3135} 3136 btx=analogRead(JoyStick_X); 3137controlbluetooth(); 3138 // delay(50); 3139 if(btx<400){ 3140 3141 break;} 3142 3143// helice***************************************** 3144touslesservosacetangle(degremax-10,20); 3145 3146 3147 3148byte xx0[12]{0,1,2,3,4,5,18,19,20,21,22,23};//valeur de dparts des lignes de xx0/yy0 xx1/yy1 3149byte yy0[12]{23,23,23,23,23,23,23,23,23,23,23,23}; 3150byte xx1[12]{23,22,21,20,19,18,5,4,3,2,1,0}; 3151byte yy1[12]{0,0,0,0,0,0,0,0,0,0,0,0}; 3152byte incrxx0[4]{1,1,1,1};// incrment de la dernire ligne puis de la premire ligne de la 1re pale puis idem de la 2me pale 3153byte incryy0[4]{0,0,0,0}; 3154byte incrxx1[4]{-1,-1,-1,-1}; 3155byte incryy1[4]{0,0,0,0}; 3156byte debutpale[2]{0,6};//le dbut de la pale 1 est le 0 me du tableau des dparts de ligne, la pale 2 est la 6me de ces mmes tabelaux 3157byte finpale[2]{5,11};//la fin de la pale 1 est le 5 me du tableau des dparts de ligne, la pale 2 est la 11me de ces mmes tabelaux 3158byte index=0; 3159byte noligne=0; 3160 3161for(int noligne=0;noligne<12;noligne++){ 3162 writeLine(xx0[noligne],yy0[noligne],xx1[noligne],yy1[noligne],70,20,vitesse);} 3163 3164for(int tours=1;tours<150;tours++){ 3165for(byte nbrpale=0;nbrpale<2;nbrpale++){ 3166noligne=debutpale[nbrpale];//on efface la ligne 0 puis la 18 3167 index=nbrpale*2; //on efface la ligne 0 puis la ligne 18 qui est l'lment2 dans incrxx0 3168 3169writeLine(xx0[noligne],yy0[noligne],xx1[noligne],yy1[noligne],degremax-10,20,vitesse); 3170//delay(2000); 3171if((xx0[noligne]<=0)&(yy0[noligne]<=0)){incrxx0[index]=0;incryy0[index]=1;} 3172if((xx0[noligne]<=0)&(yy0[noligne]>=23)){incrxx0[index]=1;incryy0[index]=0;} 3173if((xx0[noligne]>=23)&(yy0[noligne]>=23)){incrxx0[index]=0;incryy0[index]=-1;} 3174if((xx0[noligne]>=23)&(yy0[noligne]<=0)){incrxx0[index]=-1;incryy0[index]=0;} 3175 3176if((xx1[noligne]<=0)&(yy1[noligne]<=0)){incrxx1[index]=0;incryy1[index]=1;} 3177if((xx1[noligne]<=0)&(yy1[noligne]>=23)){incrxx1[index]=1;incryy1[index]=0;} 3178if((xx1[noligne]>=23)&(yy1[noligne]>=23)){incrxx1[index]=0;incryy1[index]=-1;} 3179if((xx1[noligne]>=23)&(yy1[noligne]<=0)){incrxx1[index]=-1;incryy1[index]=0;} 3180 3181xx0[noligne]=xx0[noligne]+incrxx0[index]; 3182yy0[noligne]=yy0[noligne]+incryy0[index]; 3183xx1[noligne]=xx1[noligne]+incrxx1[index]; 3184yy1[noligne]=yy1[noligne]+incryy1[index]; 3185 3186 3187xx0[noligne]=constrain(xx0[noligne], 0, 23); 3188yy0[noligne]=constrain(yy0[noligne], 0, 23); 3189xx1[noligne]=constrain(xx1[noligne], 0, 23); 3190yy1[noligne]=constrain(yy1[noligne], 0, 23); 3191 3192//******************* 3193//noligne=(sizeof(xx0)/sizeof(xx0[0]))-1;// on ajoute la premire ligne 3194noligne=finpale[nbrpale]; 3195 index=(nbrpale*2)+1; //on rajoute la ligne 7 puis la ligne 23 qui est l'lment2 dans incrxx0 3196 3197writeLine(xx0[noligne],yy0[noligne],xx1[noligne],yy1[noligne],70,20,vitesse); 3198 3199 3200if((xx0[noligne]<=0)&(yy0[noligne]<=0)){incrxx0[index]=0;incryy0[index]=1;} 3201if((xx0[noligne]<=0)&(yy0[noligne]>=23)){incrxx0[index]=1;incryy0[index]=0;} 3202if((xx0[noligne]>=23)&(yy0[noligne]>=23)){incrxx0[index]=0;incryy0[index]=-1;} 3203if((xx0[noligne]>=23)&(yy0[noligne]<=0)){incrxx0[index]=-1;incryy0[index]=0;} 3204 3205if((xx1[noligne]<=0)&(yy1[noligne]<=0)){incrxx1[index]=0;incryy1[index]=1;} 3206if((xx1[noligne]<=0)&(yy1[noligne]>=23)){incrxx1[index]=1;incryy1[index]=0;} 3207if((xx1[noligne]>=23)&(yy1[noligne]>=23)){incrxx1[index]=0;incryy1[index]=-1;} 3208if((xx1[noligne]>=23)&(yy1[noligne]<=0)){incrxx1[index]=-1;incryy1[index]=0;} 3209 3210xx0[noligne]=xx0[noligne]+incrxx0[index]; 3211yy0[noligne]=yy0[noligne]+incryy0[index]; 3212xx1[noligne]=xx1[noligne]+incrxx1[index]; 3213yy1[noligne]=yy1[noligne]+incryy1[index]; 3214 3215 3216xx0[noligne]=constrain(xx0[noligne], 0, 23); 3217yy0[noligne]=constrain(yy0[noligne], 0, 23); 3218xx1[noligne]=constrain(xx1[noligne], 0, 23); 3219yy1[noligne]=constrain(yy1[noligne], 0, 23); 3220 3221} 3222} 3223 3224 3225 3226 3227 btx=analogRead(JoyStick_X); 3228controlbluetooth(); 3229 // delay(50); 3230 if(btx<400){ 3231 break;} 3232 3233 3234 3235// 1 rond qui se rpte 3236 3237touslesservosacetangle(degremax-10,30); 3238 3239for(int tours=1;tours<5;tours++){ 3240 3241int x0=random(8,16); 3242int y0=random(8,16); 3243 3244for(int rayon=1;rayon<10;rayon++){ 3245drawCircle(x0,y0,rayon,70,20,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3246delay(50); 3247} 3248for(int rayon=1;rayon<11;rayon++){ 3249drawCircle(x0,y0,rayon-1,degremax-10,20,vitesse);//drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) 3250delay(50); 3251} 3252} 3253 btx=analogRead(JoyStick_X); 3254controlbluetooth(); 3255 // delay(50); 3256 if(btx<400){ 3257 break;} 3258 3259// rideau********************************************* 3260 3261touslesservosacetangle(degremax-10,30); 3262 3263for(int tours=1;tours<2;tours++){ 3264 3265for(int y0=0;y0<24;y0++){ 3266writeLine(0,y0,23,y0,70,10,vitesse); 3267delay(50); 3268} 3269 3270delay(50); 3271 3272for(int y0=0;y0<24;y0++){ 3273writeLine(0,y0,23,y0,degremax-10,10,vitesse); 3274delay(50); 3275} 3276 3277delay(50); 3278 3279for(int x0=0;x0<24;x0++){ 3280writeLine(x0,0,x0,23,70,10,vitesse); 3281delay(50); 3282} 3283 3284delay(50); 3285for(int x0=0;x0<24;x0++){ 3286writeLine(x0,0,x0,23,degremax-10,10,vitesse); 3287delay(50); 3288} 3289 3290delay(50); 3291 3292} 3293 3294 3295 btx=analogRead(JoyStick_X); 3296controlbluetooth(); 3297 // delay(50); 3298 if(btx<400){ 3299 break;} 3300 3301} 3302touslesservosacetangle(90,20); 3303} 3304//******************************************************************************************************* 3305//******************************************************************************************************* 3306//******************************************************************************************************* 3307// cercle 3308//************************************************************************************* 3309 3310 3311 3312void drawCircle(int x0, int y0, int r, int degre,byte acceleration,byte vitesse) { 3313 if(r>0){ 3314 int f = 1 - r; 3315 int ddF_x = 1; 3316 int ddF_y = -2 * r; 3317 int x = 0; 3318 int y = r; 3319 3320 3321bougeservo(x0, y0 + r,degre,acceleration, vitesse);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 3322bougeservo(x0, y0 - r,degre,acceleration, vitesse);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 3323bougeservo(x0+r, y0,degre,acceleration, vitesse);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 3324bougeservo(x0-r, y0,degre,acceleration, vitesse);//moveservo(byte x, byte y, int valeur, byte acceleration, byte vitesse) 3325 3326 3327 3328 3329 while (x<y) { 3330 if (f >= 0) { 3331 y--; 3332 ddF_y += 2; 3333 f += ddF_y; 3334 } 3335 x++; 3336 ddF_x += 2; 3337 f += ddF_x; 3338bougeservo(x0+x, y0 + y,degre,acceleration, vitesse); 3339bougeservo(x0-x, y0 + y,degre,acceleration, vitesse); 3340bougeservo(x0+x, y0 - y,degre,acceleration, vitesse); 3341bougeservo(x0-x, y0 - y,degre,acceleration, vitesse); 3342bougeservo(x0+y, y0 + x,degre,acceleration, vitesse); 3343bougeservo(x0-y, y0 + x,degre,acceleration, vitesse); 3344bougeservo(x0+y, y0 - x,degre,acceleration, vitesse); 3345bougeservo(x0-y, y0 - x,degre,acceleration, vitesse); 3346 3347 } 3348 } 3349} 3350 3351 3352/**************************************************************************/ 3353/*! 3354 @brief Write a line. Bresenham's algorithm - thx wikpedia 3355 @param x0 Start point x coordinate 3356 @param y0 Start point y coordinate 3357 @param x1 End point x coordinate 3358 @param y1 End point y coordinate 3359 @param color 16-bit 5-6-5 Color to draw with 3360*/ 3361/**************************************************************************/ 3362void writeLine(byte x0, byte y0, byte x1, byte y1, byte degre,byte acceleration,byte vitesse){ 3363 3364 3365if((x0==x1)or(y0==y1)){ 3366 3367if(y0==y1){// on dessine une ligne horizontale 3368byte longeur=abs(x1-x0)+1; 3369for(byte x=0;x<longeur;x++){ 3370 bougeservo(x+x0, y0,degre,acceleration, vitesse); }} 3371 3372 3373else{// on dessine une ligne verticale 3374 byte longueur=abs(y1-y0)+1; 3375for(byte y=0; y<longueur; y++){ 3376 3377 bougeservo(x0, y+y0,degre,acceleration, vitesse);} 3378 3379} 3380 3381 3382} 3383else{// c'est ni une horizontale ni une verticale 3384 int steep = abs(y1 - y0) > abs(x1 - x0); 3385 3386 if (steep) { 3387 swap(x0, y0); 3388 swap(x1, y1); 3389 } 3390 3391 if (x0 > x1) { 3392 swap(x0, x1); 3393 swap(y0, y1); 3394 } 3395 3396 int dx, dy; 3397 dx = x1 - x0; 3398 dy = abs(y1 - y0); 3399 3400 int err = dx / 2; 3401 int ystep; 3402 3403 if (y0 < y1) { 3404 ystep = 1; 3405 } else { 3406 ystep = -1; 3407 } 3408 3409 for (; x0<=x1; x0++) { 3410 if (steep) { 3411 3412 3413 bougeservo(y0, x0,degre,acceleration, vitesse); 3414 3415 3416 } else { 3417 3418 3419 bougeservo(x0, y0,degre,acceleration, vitesse); 3420 3421 } 3422 err -= dy; 3423 if (err < 0) { 3424 y0 += ystep; 3425 err += dx; 3426 } 3427 } 3428} 3429} 3430 3431//********************************************************************************************************************** 3432//********************************************************************************************************************** 3433 3434//********************************************************************************************************************** 3435//********************************************************************************************************************** 3436 3437void bougeservo(int x, int y, byte degre, byte acceleration, byte vitesse)//ATTENTION si acceleration=0 elle passe le rglage de l'acceleration; a va plus vite 3438{ 3439 /* setSpeed takes channel number you want to limit and the 3440 speed limit in units of (1/4 microseconds)/(10 milliseconds). 3441 3442 A speed of 0 makes the speed unlimited, so that setting the 3443 target will immediately affect the position. Note that the 3444 actual speed at which your servo moves is also limited by the 3445 design of the servo itself, the supply voltage, and mechanical 3446 loads. */ 3447 /* setAcceleration takes channel number you want to limit and 3448 the acceleration limit value from 0 to 255 in units of (1/4 3449 microseconds)/(10 milliseconds) / (80 milliseconds). 3450 3451 A value of 0 corresponds to no acceleration limit. An 3452 acceleration limit causes the speed of a servo to slowly ramp 3453 up until it reaches the maximum speed, then to ramp down again 3454 as the position approaches the target, resulting in relatively 3455 smooth motion from one point to another. */ 3456if((x>=0)&&(y>=0)&&(x<24)&&(y<24)){ 3457 3458 3459int valeur=(degre-90)+ angleetalon90[y][x];// 3460valeur=constrain(valeur, degremin, degremax);//pour des mouvements de degremin degremax 3461valeur=map(valeur, 0, 180, valeurmin, valeurmax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 3462valeur=constrain(valeur, valeurmin, valeurmax); 3463 3464 if(acceleration!=0){ 3465device[x].setSpeed(y, vitesse); 3466device[x].setAcceleration(y, acceleration); 3467 } 3468device[x].setTarget(y, valeur); 3469 3470 3471// pour dessin de cercle avec process 3472//valeur=map(valeur, valeurmax, valeurmin, 0, 180); 3473//Serial.print(valeur);// 3474//Serial.print(",");// angle,x,y avec un retour la ligne println('\ 3475' sur processing) 3476//Serial.print(x); 3477//Serial.print(","); 3478//Serial.println(y);// avec retour la ligne qui est detect par processing 3479 3480} 3481} 3482//**************************************************************************************************************** 3483void touslesservosacetangle(byte degre, byte acceleration)// cette fonction est utilise pour mettre a une valeur 3484// tous les servos , elle permet de rgler une fois pour toute l'acceleration, aprson est plus oblig de la redonner pour chaque servos , a permet d'aller plus vite 3485{ 3486 for(int y=0;y<24;y++){ 3487 for(int x=0;x<24;x++){ 3488 3489if(acceleration==0){acceleration=30;}// 3490 3491bougeservo(x, y,degre,acceleration, 0); 3492}} 3493} 3494 3495//***************************************************************************************************************** 3496 3497//***************************************************************************** 3498//***************************************************************************** 3499//**************************** Balle ******************************* 3500//***************************************************************************** 3501//***************************************************************************** 3502void balle() { 3503 lcdaffiche("balle",""); 3504 3505int tabballex[6] {2,3,4,10,11,12};// 2 balles par exemple tableau des coordonnes des 2 balles en x 3506int tabballey[6] {1,1,1,1,1,1};// 2 balles par exemple tableau des coordonnes des 2 balles en y au dbut ne pas faire toucher le bord 3507int tabincrementx[6] {1,1,1,-2,-2,-2};// 3508int tabincrementy[6] {2,2,2,1,1,1}; 3509int valeur; 3510 3511 3512touslesservosacetangle(degremax-10, 100);//tousleservosacetangle(int degre, byte acceleration) 3513while(nomenualain==9){ 3514 3515 3516 for (int z = 0; z < 6; z++){ //pour toutes les balles faire bouger 3517 3518// ouverture 3519bougeservo(tabballex[z], tabballey[z],50,0, 0); 3520} 3521delay(10); 3522 3523 3524 for (int z = 0; z < 6; z++){ //pour toutes les balles faire bouger 3525// fermeture 3526 bougeservo(tabballex[z], tabballey[z],degremax-10,5, 0); 3527 3528} 3529delay(50); 3530 3531 for (int z = 0; z < 6; z++){ //pour toutes les balles faire bouger 3532 // ctr des incrments 3533if(tabballex[z]>=23){tabincrementx[z]=-tabincrementx[z];} 3534if(tabballex[z]<=0){tabincrementx[z]=-tabincrementx[z];} 3535if(tabballey[z]>=23){tabincrementy[z]=-tabincrementy[z];} 3536if(tabballey[z]<=0){tabincrementy[z]=-tabincrementy[z];} 3537 3538 3539tabballex[z]=tabballex[z]+tabincrementx[z]; 3540tabballey[z]=tabballey[z]+tabincrementy[z]; 3541 } 3542 3543 3544 3545 3546 3547 btx=analogRead(JoyStick_X); 3548controlbluetooth(); 3549 // delay(50); 3550 if(btx<400){ 3551 break;} 3552 3553} 3554touslesservosacetangle(90,30); 3555 3556} 3557 3558 3559//************************************************* 3560 3561void liretableaudebit(uint32_t tableaudebit[24],int decalagex,int decalagey){ 3562 3563int valeur=90; 3564 3565for(int y=0;y<24;y++){ 3566 for(int x=0;x<24;x++){ 3567 3568byte s=0; 3569 3570s=bitRead(tableaudebit[y+decalagey],x+8+decalagex); 3571 3572 3573if(s==1){ 3574valeur=70; 3575} 3576else 3577{ 3578valeur=140; 3579} 3580 3581valeur=(valeur-90)+ angleetalon90[y][x];// 3582valeur=constrain(valeur, degremin, degremax); 3583valeur=map(valeur, 0, 180, valeurmin, valeurmax);//map(value, fromLow, fromHigh, toLow, toHigh) valeur entire 3584device[x].setTarget(y, valeur); 3585 3586 3587}} 3588} 3589 3590 3591//********************* 3592 3593void lirepixel(){ 3594 3595touslesservosacetangle(90,60); 3596int x=-10; 3597 3598while(nomenualain==10){ 3599 3600 3601x=x+1; 3602 3603liretableaudebit(pacmanouvert,x,0); 3604 3605delay(150); 3606liretableaudebit(pacmanferme,x,0); 3607delay(150); 3608 3609if(x>20){x=-10;} 3610 3611 btx=analogRead(JoyStick_X); 3612controlbluetooth(); 3613 // delay(50); 3614 if(btx<400){ 3615 break;} 3616 3617} 3618touslesservosacetangle(90,30); 3619 3620} 3621 3622//************************************************** 3623void envoiimagesurprocessing(int k,byte x, byte y){ 3624 //// pour envoi de la photo sur processing 24x24 avec Serial.begin(115200);// on ne peut pas aller plus vite pour recvoir des imput de processing 3625Serial.print(k);// 3626Serial.print(",");// angle,x,y avec un retour la ligne println('\ 3627' sur processing) 3628Serial.print(x); 3629Serial.print(","); 3630Serial.println(y);// avec retour la ligne qui est detect par processing 3631// fin d' envoi de la photo sur processing 3632 3633} 3634 3635
registre
arduino
1// definition des regsitres de la camera 2// Register addresses and values 3// on utilise les valeurs de qqcif au lieu de celle de qqvga, mais on utilise la commande qqvga pour faire les photos avec les valeurs de qqcif 4 5//Cablage 6//3.3 v sur 3.3 arduino GND sur GND 7//SIOC sur SCL 21srduino SIOD sur SDA 20 arduino 8//Vsync sur pin 22 verticalsync Href sur rien 9//D7 sur pin28 D6 sur 29 10//D5 sur pin 30 D4 sur 31 11//D3 sur pin32 D2 sur 33 12//D1 sur pin34 D0 sur 35 13//RST sur rien PWDN sur rien 14//STR sur rien RCK(ou RCLK) sur 26 output fifo buffer output clock 15//WR sur 24 outputwriteenable OE sur GND 16//WRST sur 25 outputwritepointerreset RRST sur 23 outpoutreadpointerreset 17 18 19#define swap(a,b){int t=a;a=b;b=t;}//utilis pour dessiner une ligne 20 21#define CLKRC 0x11 22#define CLKRC_VALUE_VGA 0x01 // Raw Bayer 23#define CLKRC_VALUE_QVGA 0x01 24#define CLKRC_VALUE_QQVGA 0x01// pour qqcif pareil 25#define CLKRC_VALUE_NIGHTMODE_FIXED 0x03 // Fixed Frame 26#define CLKRC_VALUE_NIGHTMODE_AUTO 0x80 // Auto Frame Rate Adjust 27 28#define COM7 0x12 29#define COM7_VALUE_VGA 0x01 // Raw Bayer 30#define COM7_VALUE_VGA_COLOR_BAR 0x03 // Raw Bayer 31#define COM7_VALUE_VGA_PROCESSED_BAYER 0x05 // Processed Bayer 32#define COM7_VALUE_QVGA 0x00 33#define COM7_VALUE_QVGA_COLOR_BAR 0x02 34#define COM7_VALUE_QVGA_PREDEFINED_COLOR_BAR 0x12 35#define COM7_VALUE_QQVGA 0x00// pour qqcif pareil 36#define COM7_VALUE_QQVGA_COLOR_BAR 0x02 37#define COM7_VALUE_QCIF 0x08 // Predefined QCIF format 38#define COM7_VALUE_COLOR_BAR_QCIF 0x0A // Predefined QCIF Format with ColorBar 39#define COM7_VALUE_RESET 0x80 40 41 42#define COM3 0x0C 43#define COM3_VALUE_VGA 0x00 // Raw Bayer 44#define COM3_VALUE_QVGA 0x04 45//#define COM3_VALUE_QQVGA 0x04 // From Docs 46#define COM3_VALUE_QQVGA 0x0C // essais pour qqcif 47#define COM3_VALUE_QQVGA_SCALE_ENABLED 0x0C // Enable Scale and DCW 48#define COM3_VALUE_QCIF 0x0C // Enable Scaling and enable DCW 49 50#define COM14 0x3E 51#define COM14_VALUE_VGA 0x00 // Raw Bayer 52#define COM14_VALUE_QVGA 0x19 53//#define COM14_VALUE_QQVGA 0x1A 54#define COM14_VALUE_QQVGA 0x12 //essais pour qqcif0x12 55#define COM14_VALUE_MANUAL_SCALING 0x08 // Manual Scaling Enabled 56#define COM14_VALUE_NO_MANUAL_SCALING 0x00 // Manual Scaling DisEnabled 57 58#define SCALING_XSC 0x70 59#define SCALING_XSC_VALUE_VGA 0x3A // Raw Bayer 60#define SCALING_XSC_VALUE_QVGA 0x3A 61#define SCALING_XSC_VALUE_QQVGA 0x3A// pareil pour qqcif 62#define SCALING_XSC_VALUE_QQVGA_SHIFT1 0x3A 63#define SCALING_XSC_VALUE_COLOR_BAR 0xBA 64#define SCALING_XSC_VALUE_QCIF_COLOR_BAR_NO_SCALE 0x80 // Predefined QCIF with Color Bar and NO Scaling 65 66#define SCALING_YSC 0x71 67#define SCALING_YSC_VALUE_VGA 0x35 // Raw Bayer 68#define SCALING_YSC_VALUE_QVGA 0x35 69#define SCALING_YSC_VALUE_QQVGA 0x35// pareil pour qqcif 70#define SCALING_YSC_VALUE_COLOR_BAR 0x35 // 8 bar color bar 71#define SCALING_YSC_VALUE_COLOR_BAR_GREY 0xB5 // fade to grey color bar 72#define SCALING_YSC_VALUE_COLOR_BAR_SHIFT1 0xB5 // fade to grey color bar 73#define SCALING_YSC_VALUE_QCIF_COLOR_BAR_NO_SCALE 0x00 // Predefined QCIF with Color Bar and NO Scaling 74 75#define SCALING_DCWCTR 0x72 76#define SCALING_DCWCTR_VALUE_VGA 0x11 // Raw Bayer 77#define SCALING_DCWCTR_VALUE_QVGA 0x11 78#define SCALING_DCWCTR_VALUE_QQVGA 0x22 // pareil pour qqcif 79 80#define SCALING_PCLK_DIV 0x73 81#define SCALING_PCLK_DIV_VALUE_VGA 0xF0 // Raw Bayer 82#define SCALING_PCLK_DIV_VALUE_QVGA 0xF1 83#define SCALING_PCLK_DIV_VALUE_QQVGA 0xF2// pareil pour qqcif 84 85#define SCALING_PCLK_DELAY 0xA2 86#define SCALING_PCLK_DELAY_VALUE_VGA 0x02 // Raw Bayer 87#define SCALING_PCLK_DELAY_VALUE_QVGA 0x02 88//#define SCALING_PCLK_DELAY_VALUE_QQVGA 0x02 89#define SCALING_PCLK_DELAY_VALUE_QQVGA 0x2A//essais pour qqcif 90 91// Controls YUV order Used with COM13 92// Need YUYV format for Android Decoding- Default value is 0xD 93#define TSLB 0x3A 94#define TSLB_VALUE_YUYV_AUTO_OUTPUT_WINDOW_ENABLED 0x01 // No custom scaling 95#define TSLB_VALUE_YUYV_AUTO_OUTPUT_WINDOW_DISABLED 0x00 // For adjusting HSTART, etc. YUYV format 96#define TSLB_VALUE_UYVY_AUTO_OUTPUT_WINDOW_DISABLED 0x08 97#define TSLB_VALUE_TESTVALUE 0x04 // From YCbCr Reference 98 99 100// Default value is 0x88 101// ok if you want YUYV order, no need to change 102#define COM13 0x3D 103#define COM13_VALUE_DEFAULT 0x88 104#define COM13_VALUE_NOGAMMA_YUYV 0x00 105#define COM13_VALUE_GAMMA_YUYV 0x80 106#define COM13_VALUE_GAMMA_YVYU 0x82 107#define COM13_VALUE_YUYV_UVSATAUTOADJ_ON 0x40 108 109 110 111// Works with COM4 112#define COM17 0x42 113#define COM17_VALUE_AEC_NORMAL_NO_COLOR_BAR 0x00 114#define COM17_VALUE_AEC_NORMAL_COLOR_BAR 0x08 // Activate Color Bar for DSP 115 116#define COM4 0x0D 117 118// RGB Settings and Data format 119#define COM15 0x40 120 121 122// Night Mode 123#define COM11 0x3B 124#define COM11_VALUE_NIGHTMODE_ON 0x80 // Night Mode 125#define COM11_VALUE_NIGHTMODE_OFF 0x00 126#define COM11_VALUE_NIGHTMODE_ON_EIGHTH 0xE0 // Night Mode 1/8 frame rate minimum 127#define COM11_VALUE_NIGHTMODE_FIXED 0x0A 128#define COM11_VALUE_NIGHTMODE_AUTO 0xEA // Night Mode Auto Frame Rate Adjust 129 130 131// Color Matrix Control YUV 132#define MTX1 0x4f 133#define MTX1_VALUE 0x80 134 135#define MTX2 0x50 136#define MTX2_VALUE 0x80 137 138#define MTX3 0x51 139#define MTX3_VALUE 0x00 140 141#define MTX4 0x52 142#define MTX4_VALUE 0x22 143 144#define MTX5 0x53 145#define MTX5_VALUE 0x5e 146 147#define MTX6 0x54 148#define MTX6_VALUE 0x80 149 150#define CONTRAS 0x56 151#define CONTRAS_VALUE 0x40// contratse 0, 0x40 152//#define CONTRAS_VALUE 0x50// essais contratse +1 153//#define CONTRAS_VALUE 0x60// encore +2 154//#define CONTRAS_VALUE 0x38// encore -1 155//#define CONTRAS_VALUE 0x30// encore -2 156#define MTXS 0x58 157#define MTXS_VALUE 0x9e 158 159 160 161// COM8 162#define COM8 0x13// si le bit[0] est 0 mode d'exposition est sur manuel 163#define COM8_VALUE_AWB_OFF 0xE5// simple automatic white balance off 164#define COM8_VALUE_AWB_ON 0xE7//0xE0= pour desactiver AEC,AGC,AWB// 0xE7=simple automatic white balance on 165 166//Sunny 167//write_i2c(0x13, 0xe5); //AWB off write_i2c(0x01, 0x5a); write_i2c(0x02, 0x5c); 168//Cloudy 169//write_i2c(0x13, 0xe5); //AWB off write_i2c(0x01, 0x58); write_i2c(0x02, 0x60); 170//Office 171//write_i2c(0x13, 0xe5); //AWB off write_i2c(0x01, 0x84); write_i2c(0x02, 0x4c); 172//Home 173//i2c_salve_Address = 0x42; 174 175// Automatic White Balance 176#define AWBC1 0x43 177#define AWBC1_VALUE 0x14 178 179#define AWBC2 0x44 180#define AWBC2_VALUE 0xf0 181 182#define AWBC3 0x45 183#define AWBC3_VALUE 0x34 184 185#define AWBC4 0x46 186#define AWBC4_VALUE 0x58 187 188#define AWBC5 0x47 189#define AWBC5_VALUE 0x28 190 191#define AWBC6 0x48 192#define AWBC6_VALUE 0x3a 193 194#define AWBC7 0x59 195#define AWBC7_VALUE 0x88 196 197#define AWBC8 0x5A 198#define AWBC8_VALUE 0x88 199 200#define AWBC9 0x5B 201#define AWBC9_VALUE 0x44 202 203#define AWBC10 0x5C 204#define AWBC10_VALUE 0x67 205 206#define AWBC11 0x5D 207#define AWBC11_VALUE 0x49 208 209#define AWBC12 0x5E 210#define AWBC12_VALUE 0x0E 211 212#define AWBCTR3 0x6C 213#define AWBCTR3_VALUE 0x0A 214 215#define AWBCTR2 0x6D 216#define AWBCTR2_VALUE 0x55 217 218#define AWBCTR1 0x6E 219#define AWBCTR1_VALUE 0x11 220 221#define AWBCTR0 0x6F 222#define AWBCTR0_VALUE_NORMAL 0x9F// simple automatic white balance 223#define AWBCTR0_VALUE_ADVANCED 0x9E// advance automatic white balance 224 225 226// Gain 227#define COM9 0x14 228#define COM9_VALUE_MAX_GAIN_128X 0x6A 229#define COM9_VALUE_4XGAIN 0x10 // 0001 0000 230 231#define BLUE 0x01 // AWB Blue Channel Gain 232#define BLUE_VALUE 0x40 233 234#define RED 0x02 // AWB Red Channel Gain 235#define RED_VALUE 0x40 236 237#define GGAIN 0x6A // AWB Green Channel Gain 238#define GGAIN_VALUE 0x40 239 240#define COM16 0x41 241#define COM16_VALUE 0x08 // AWB Gain on 242 243#define GFIX 0x69 244#define GFIX_VALUE 0x00 245 246// Edge Enhancement Adjustment 247#define EDGE 0x3f 248#define EDGE_VALUE 0x00 249 250#define REG75 0x75 251#define REG75_VALUE 0x03 252 253#define REG76 0x76 254#define REG76_VALUE 0xe1 255 256// DeNoise 257#define DNSTH 0x4c 258#define DNSTH_VALUE 0x00 259 260#define REG77 0x77 261#define REG77_VALUE 0x00 262 263// Denoise and Edge Enhancement 264#define COM16_VALUE_DENOISE_OFF_EDGE_ENHANCEMENT_OFF_AWBGAIN_ON 0x08 // Denoise off, AWB Gain on 265#define COM16_VALUE_DENOISE_ON__EDGE_ENHANCEMENT_OFF__AWBGAIN_ON 0x18 266#define COM16_VALUE_DENOISE_OFF__EDGE_ENHANCEMENT_ON__AWBGAIN_ON 0x28 267#define COM16_VALUE_DENOISE_ON__EDGE_ENHANCEMENT_ON__AWBGAIN_ON 0x38 // Denoise on, Edge Enhancement on, AWB Gain on 268 269 270// 30FPS Frame Rate , PCLK = 24Mhz 271#define CLKRC_VALUE_30FPS 0x80 272 273#define DBLV 0x6b 274#define DBLV_VALUE_30FPS 0x0A 275 276#define EXHCH 0x2A 277#define EXHCH_VALUE_30FPS 0x00 278 279#define EXHCL 0x2B 280#define EXHCL_VALUE_30FPS 0x00 281 282#define DM_LNL 0x92 283#define DM_LNL_VALUE_30FPS 0x00 284 285#define DM_LNH 0x93 286#define DM_LNH_VALUE_30FPS 0x00 287 288#define COM11_VALUE_30FPS 0x0A 289 290 291// Saturation Control 292#define SATCTR 0xc9 293#define SATCTR_VALUE 0x60 294 295 296 297 298// AEC/AGC - Automatic Exposure/Gain Control J'ai augment les limites de la stable operating region afin que a ne change pas trop la qte de lumire 299 300// ------------------ VPT[7:4] mis au max=240(au lieu de 224); controle zone, en dehors de cette zone , il ya de grande compensation de gain et de temps de pose, en dedans de cette zone de petite correction 301// | | 302// | ---------- | AEW mis 239 (au lieu de 149) 303// | | | | stable operating region, l'intrieur de cette rgion il n'y a plus de changement de gain ni de temps de pose 304// | ---------- | AEB mis 1 (au lieu de 51) 305// | | 306// ------------------ VPT[3:0] mis min = 0 (au lieu de 3) 307 308 309 310// AEC/AGC - Automatic Exposure/Gain Control J'ai augment les limites de la stable operating region afin que a ne change pas trop la qte de lumire 311#define GAIN 0x00 312#define GAIN_VALUE 0x00 313 314#define AEW 0x24 315#define AEW_VALUE 0xFF//valeur initial= 0x95 stable operating region upper limit= 149 en dessous dans laquelle il n' ya plus de correction 316//j'ai mis EF=239 c'est pres de zone control qui est 240=F sur les 4 bits de gauche ce qui fait qu'il ya trs peu de petite correction(il ya en a entre 239 et 240) 317// pour finir j'ai mis 240 =FF qui fait qu'il n'y a plus du tout de grosse correction 318#define AEB 0x25 319#define AEB_VALUE 0x00//valeur initial= 0x33// stable operating region lower limit= 51 au dessus dans laquelle il n' ya plus de correction 320// j'ai mis 1 c'est tout prs de controlezone ce qui fait qu'il ya trs peu de petite correction(il ya en a entre 0 et 1) 321// pour finir j'ai mis 0=00 qui fait qu'il n'y a plus du tout de grosse correction 322#define VPT 0x26 // 323#define VPT_VALUE 0xF0//valeur initiale= 0xe3 324// control zone (en dehors de cette zonede grande correction , en dedans de cette zone de petite correction) 325// les deux valeurs sont dans vpt upper limit VPT[7:4] et lower limit VPT[3:0] e3= upper =224 et lower =3 326// j'ai mis F0= F=le max en upper limit(240, les 4 bits de gauche) 0 le min en lower limit, ce qui veut dire qu'il ne sort jamais du control zone et donc il n'y a pas de grande correction de gain et de temps de pose 327/* 328// Gamma 329#define SLOP 0x7a 330#define SLOP_VALUE 0x20 331#define GAM1 0x7b 332#define GAM1_VALUE 0x10 333#define GAM2 0x7c 334#define GAM2_VALUE 0x1e 335#define GAM3 0x7d 336#define GAM3_VALUE 0x35 337#define GAM4 0x7e 338#define GAM4_VALUE 0x5a 339#define GAM5 0x7f 340#define GAM5_VALUE 0x69 341#define GAM6 0x80 342#define GAM6_VALUE 0x76 343#define GAM7 0x81 344#define GAM7_VALUE 0x80 345#define GAM8 0x82 346#define GAM8_VALUE 0x88 347#define GAM9 0x83 348#define GAM9_VALUE 0x8f 349#define GAM10 0x84 350#define GAM10_VALUE 0x96 351#define GAM11 0x85 352#define GAM11_VALUE 0xa3 353#define GAM12 0x86 354#define GAM12_VALUE 0xaf 355#define GAM13 0x87 356#define GAM13_VALUE 0xc4 357#define GAM14 0x88 358#define GAM14_VALUE 0xd7 359#define GAM15 0x89 360#define GAM15_VALUE 0xe8 361*/ 362 363 364 365// AEC/AGC Control- Histogram 366#define HAECC1 0x9f 367#define HAECC1_VALUE 0x78 368 369#define HAECC2 0xa0 370#define HAECC2_VALUE 0x68 371 372#define HAECC3 0xa6 373#define HAECC3_VALUE 0xd8 374 375#define HAECC4 0xa7 376#define HAECC4_VALUE 0xd8 377 378#define HAECC5 0xa8 379#define HAECC5_VALUE 0xf0 380 381#define HAECC6 0xa9 382#define HAECC6_VALUE 0x90 383 384#define HAECC7 0xaa // AEC Algorithm selection 385#define HAECC7_VALUE_HISTOGRAM_AEC_ON 0x94 386#define HAECC7_VALUE_AVERAGE_AEC_ON 0x00 387 388 389 390/* 391// Gamma 392#define SLOP 0x7a 393#define SLOP_VALUE 0x20 394#define GAM1 0x7b 395#define GAM1_VALUE 0x10 396#define GAM2 0x7c 397#define GAM2_VALUE 0x1e 398#define GAM3 0x7d 399#define GAM3_VALUE 0x35 400#define GAM4 0x7e 401#define GAM4_VALUE 0x5a 402#define GAM5 0x7f 403#define GAM5_VALUE 0x69 404#define GAM6 0x80 405#define GAM6_VALUE 0x76 406#define GAM7 0x81 407#define GAM7_VALUE 0x80 408#define GAM8 0x82 409#define GAM8_VALUE 0x88 410#define GAM9 0x83 411#define GAM9_VALUE 0x8f 412#define GAM10 0x84 413#define GAM10_VALUE 0x96 414#define GAM11 0x85 415#define GAM11_VALUE 0xa3 416#define GAM12 0x86 417#define GAM12_VALUE 0xaf 418#define GAM13 0x87 419#define GAM13_VALUE 0xc4 420#define GAM14 0x88 421#define GAM14_VALUE 0xd7 422#define GAM15 0x89 423#define GAM15_VALUE 0xe8 424*/ 425 426// Array Control 427#define CHLF 0x33 428#define CHLF_VALUE 0x0b 429 430#define ARBLM 0x34 431#define ARBLM_VALUE 0x11 432 433 434 435// ADC Control 436#define ADCCTR1 0x21 437#define ADCCTR1_VALUE 0x02 438 439#define ADCCTR2 0x22 440#define ADCCTR2_VALUE 0x91 441 442#define ADC 0x37 443#define ADC_VALUE 0x1d 444 445#define ACOM 0x38 446#define ACOM_VALUE 0x71 447 448#define OFON 0x39 449#define OFON_VALUE 0x2a 450 451 452// Black Level Calibration 453#define ABLC1 0xb1 454#define ABLC1_VALUE 0x0c 455 456#define THL_ST 0xb3 457#define THL_ST_VALUE 0x82 458 459 460// Window Output 461#define HSTART 0x17 462#define HSTART_VALUE_DEFAULT 0x11 463#define HSTART_VALUE_VGA 0x13 464#define HSTART_VALUE_QVGA 0x13 465#define HSTART_VALUE_QQVGA 0x13 // Works 466 467#define HSTOP 0x18 468#define HSTOP_VALUE_DEFAULT 0x61 469#define HSTOP_VALUE_VGA 0x01 470#define HSTOP_VALUE_QVGA 0x01 471#define HSTOP_VALUE_QQVGA 0x01 // Works 472 473#define HREF 0x32 474#define HREF_VALUE_DEFAULT 0x80 475#define HREF_VALUE_VGA 0xB6 476#define HREF_VALUE_QVGA 0x24 477#define HREF_VALUE_QQVGA 0xA4 478 479#define VSTRT 0x19 480#define VSTRT_VALUE_DEFAULT 0x03 481#define VSTRT_VALUE_VGA 0x02 482#define VSTRT_VALUE_QVGA 0x02 483#define VSTRT_VALUE_QQVGA 0x02 484 485#define VSTOP 0x1A 486#define VSTOP_VALUE_DEFAULT 0x7B 487#define VSTOP_VALUE_VGA 0x7A 488#define VSTOP_VALUE_QVGA 0x7A 489#define VSTOP_VALUE_QQVGA 0x7A 490 491#define VREF 0x03 492#define VREF_VALUE_DEFAULT 0x03 493#define VREF_VALUE_VGA 0x0A 494#define VREF_VALUE_QVGA 0x0A 495#define VREF_VALUE_QQVGA 0x0A 496 497 498// I2C 499#define OV7670_I2C_ADDRESS 0x21 500#define I2C_ERROR_WRITING_START_ADDRESS 11 501#define I2C_ERROR_WRITING_DATA 22 502 503#define DATA_TOO_LONG 1 // data too long to fit in transmit buffer 504#define NACK_ON_TRANSMIT_OF_ADDRESS 2 // received NACK on transmit of address 505#define NACK_ON_TRANSMIT_OF_DATA 3 // received NACK on transmit of data 506#define OTHER_ERROR 4 // other error 507 508#define I2C_READ_START_ADDRESS_ERROR 33 509#define I2C_READ_DATA_SIZE_MISMATCH_ERROR 44 510 511#define MANU 0X67 // manual U value 512#define MANV 0X68 // manual V value 513 514 515
cameramaestro
arduino
1 2 3 4// pour voir la photo .yuv utliser le terminal et ecrire: 5// ffmpeg -f rawvideo -s 86x72 -pix_fmt yuyv422 -i /QQVGA0.YUV -f image2 -vcodec png /outputfile.png 6 7// le format utilis pour la camra est qqcif 86x72, les valeurs pour qqcif on t change dans le format qqvga 8 9#include "matrixpixel.h" 10#include <Wire.h>// pour communccation I2C pour parametrer la camera 11#include <SD.h>// pour la carte SD 12#include <SPI.h>// bus spi serie pour la maestro et bluetooth 13#include <LiquidCrystal.h>// pour le LCD afficheur 14LiquidCrystal lcd(4, 6, 10, 11, 12, 13);// initialize the library with the numbers of the interface pins 15#include "LcDef.h"// definition des valeurs de registre de la camera 16#include <PololuMaestro.h> // pour contrler les cartes servos 17 18#ifdef SERIAL_PORT_HARDWARE_OPEN 19 #define maestroSerial SERIAL_PORT_HARDWARE_OPEN 20#else 21 #include <SoftwareSerial.h> 22 SoftwareSerial maestroSerial(19, 18); 23#endif 24 25//* Next, create a Maestro object using the serial port. 26MiniMaestro maestro0(maestroSerial,255,12); 27MiniMaestro maestro1(maestroSerial,255,13); 28MiniMaestro maestro2(maestroSerial,255,14); 29MiniMaestro maestro3(maestroSerial,255,15); 30MiniMaestro maestro4(maestroSerial,255,16); 31MiniMaestro maestro5(maestroSerial,255,17); 32MiniMaestro maestro6(maestroSerial,255,18); 33MiniMaestro maestro7(maestroSerial,255,19); 34MiniMaestro maestro8(maestroSerial,255,20); 35MiniMaestro maestro9(maestroSerial,255,21); 36MiniMaestro maestro10(maestroSerial,255,22); 37MiniMaestro maestro11(maestroSerial,255,23); 38MiniMaestro maestro12(maestroSerial,255,24); 39MiniMaestro maestro13(maestroSerial,255,25); 40MiniMaestro maestro14(maestroSerial,255,26); 41MiniMaestro maestro15(maestroSerial,255,27); 42MiniMaestro maestro16(maestroSerial,255,28); 43MiniMaestro maestro17(maestroSerial,255,29); 44MiniMaestro maestro18(maestroSerial,255,30); 45MiniMaestro maestro19(maestroSerial,255,31); 46MiniMaestro maestro20(maestroSerial,255,32); 47MiniMaestro maestro21(maestroSerial,255,33); 48MiniMaestro maestro22(maestroSerial,255,34); 49MiniMaestro maestro23(maestroSerial,255,35); 50MiniMaestro device[24]{maestro0,maestro1,maestro2,maestro3,maestro4,maestro5,maestro6,maestro7,maestro8,maestro9,maestro10,maestro11,maestro12,maestro13,maestro14,maestro15,maestro16,maestro17,maestro18,maestro19,maestro20,maestro21,maestro22,maestro23}; 51 52//limite ne pas dpasser au tableau sinon le servos,les bras, les pices mobiles sont forces 53 54int degremin=25;// la plaque est tourne contre le haut 55int degremax=150;// la plaque est tourne contre le bas 56 57 58//limite ne pas dpasser par les servos sinon ils cassent, valeur plus extremes encore que degremin et degremax 59int valeurmax=map(degremax,0,180,2752,9600);// pour limiter les mouvements de degremin 160 degrmax 2400,8000 sont les valeurs min et max a donner auxservos pour 0 et 180 degrs 60int valeurmin=map(degremin,0,180,2752,9600);// pour limiter les mouvements de 30 160 degrs 2400,8000 sont les valeurs min et max a donner auxservos pour 0 et 180 degrs 61 62int valeur=valeurmin; 63const int chipSelect = 53; 64const int HardwareSSPin = 53; // For Arduino Mega 65 66 67 68// Serial Input 69const int BUFFERLENGTH = 255; 70char IncomingByte[BUFFERLENGTH]; // for incoming serial data 71 72// VGA Default 73int PHOTO_WIDTH = 640; 74int PHOTO_HEIGHT = 480; 75int PHOTO_BYTES_PER_PIXEL = 2; 76 77// Command and Parameter related Strings pour le choix de la balance des blancs, du temps de pose et du gain, du contour et du bruit, du niveau de noir 78String RawCommandLine = ""; 79String Command = "QVGA";// mais en fait c'est qqcif 72x86 80String FPSParam = "ThirtyFPS";//"NightMode" ou"ThirtyFPS" 81String AWBParam = "AAWB";//automatic white balance "AAWB" ou"SAWB"// AAWB est meilleur avec le tableau dans l'atelier avec peu de lumire 82String AECParam = "AveAEC";//automatic exposure control "AveAEC"(average) ou"HistAEC"(histogramme)// AveAEC est bien meilleur avec le tableau 83String YUVMatrixParam = "YUVMatrixOn";// ne rien mettre si on ne veut pas ou "YUVMatrixOn" 84String DenoiseParam = "DenoiseYes";//"DenoiseYes" ou"DenoiseNo"// un peu les deux pareils 85String EdgeParam = "EdgeYes";//"EdgeYes" ou"EdgeNo"// un peu les deux pareils 86String ABLCParam = "AblcOn";//"AblcOFF" ou"AblcON"// mieux avce AblOFF automatic black level control,dans la pnombre 87 88 89byte angle[24][24];// on ne peut pas avoir un tableau de byte car on additionne les valeurs de 9 pixels la fois donc 9*255, mais si on divise pixeldata/9 a fonctionne mais un peu moins prcis 90 91byte angleetalon90[24][24]; 92//byte angleetalonmax[24][24]; 93byte anglebefore[24][24]; 94 95int comptage = 0; 96boolean firstpicture=true; 97boolean macro=false; 98//// variable pour input 99const byte numChars = 32; 100char receivedChars[numChars]; 101char tempChars[numChars]; // temporary array for use when parsing 102char messageFromPC[numChars] = {0};// variables to hold the parsed data 103int integer0FromPC = 0; 104int integer1FromPC = 0; 105int integer2FromPC = 0; 106int integer3FromPC = 0; 107boolean newData = false; 108 109//// variable pour menu ett bouton 110int JoyStick_X = A0; //PS2 joystick X-axis is defined, ANALOG IN of Pin0 VRX sur A0 111int JoyStick_Y = A1; //PS2 joystick Y axis is defined, ANALOG IN of Pin1 VRY sur A1 112int JoyStick_Z = 2; //Defined PS2 joystick Z axis, pin2 SW sur 2 digital (pas analogique) 113int potentiometre=A7;// le pot est dans le pin analogique no 7 le pin du milieu du potentiometre sur A7 114int btpot; 115int btx; 116int bty; 117int btz; 118byte colonne=0; 119byte ligne=0; 120int nomenualain=0; 121byte colonneavant=0; 122byte ligneavant=0; 123//// fin de variable pour menu ett bouton 124 125 126 127 128 129enum ResolutionType 130{ 131 VGA, 132 VGAP, 133 QVGA, 134 QQVGA, 135 None 136}; 137 138ResolutionType Resolution = None; 139 140// Camera input/output pin connection to Arduino 141#define WRST 25 // Output Write Pointer Reset// ATTENTION sur le manuel 25 et 22 sont intervertis 142#define RRST 23 // Output Read Pointer Reset 143#define WEN 24 // Output Write Enable 144#define VSYNC 22 // Input Vertical Sync marking frame capture // ATTENTION sur le manuel 25 et 22 sont intervertis 145#define RCLK 26 // Output FIFO buffer output clock 146// set OE to low gnd 147 148// FIFO Ram input pins 149#define DO7 28 150#define DO6 29 151#define DO5 30 152#define DO4 31 153#define DO3 32 154#define DO2 33 155#define DO1 34 156#define DO0 35 157 158 159// SDCARD 160// MISO, MOSI, and SCK are also available in a consistent physical location on the ICSP header; 161// this is useful, for example, in designing a shield that works on the Uno and the Mega. 162// On the Arduino Mega, this is 163// 50 (MISO) 164// 51 (MOSI) 165// 52 (SCK) 166// 53 (SS) 167// VCC sur 5V 168//GND sur GND 169File myFile;// myFile=le fichier qu'on va lire sur la carte SD qui contient les valeurs 170 171 172 173byte ReadRegisterValue(int RegisterAddress) 174{ 175 byte data = 0; 176 177 Wire.beginTransmission(OV7670_I2C_ADDRESS); 178 Wire.write(RegisterAddress); 179 Wire.endTransmission(); 180 Wire.requestFrom(OV7670_I2C_ADDRESS, 1); 181 while(Wire.available() < 1); 182 data = Wire.read(); 183 184 return data; 185} 186 187void ReadRegisters() 188{ 189 byte data = 0; 190 191 data = ReadRegisterValue(CLKRC); 192 Serial.print(F("CLKRC = ")); 193 Serial.println(data,HEX); 194 195 data = ReadRegisterValue(COM7); 196 Serial.print(F("COM7 = ")); 197 Serial.println(data,HEX); 198 199 data = ReadRegisterValue(COM3); 200 Serial.print(F("COM3 = ")); 201 Serial.println(data,HEX); 202 203 data = ReadRegisterValue(COM14); 204 Serial.print(F("COM14 = ")); 205 Serial.println(data,HEX); 206 207 data = ReadRegisterValue(SCALING_XSC); 208 Serial.print(F("SCALING_XSC = ")); 209 Serial.println(data,HEX); 210 211 data = ReadRegisterValue(SCALING_YSC); 212 Serial.print(F("SCALING_YSC = ")); 213 Serial.println(data,HEX); 214 215 data = ReadRegisterValue(SCALING_DCWCTR); 216 Serial.print(F("SCALING_DCWCTR = ")); 217 Serial.println(data,HEX); 218 219 data = ReadRegisterValue(SCALING_PCLK_DIV); 220 Serial.print(F("SCALING_PCLK_DIV = ")); 221 Serial.println(data,HEX); 222 223 data = ReadRegisterValue(SCALING_PCLK_DELAY); 224 Serial.print(F("SCALING_PCLK_DELAY = ")); 225 Serial.println(data,HEX); 226 227 //data = ReadRegisterValue(COM10); 228 //Serial.print(F("COM10 (Vsync Polarity) = ")); 229 //Serial.println(data,HEX); 230 231 // default value D 232 data = ReadRegisterValue(TSLB); 233 Serial.print(F("TSLB (YUV Order- Higher Bit, Bit[3]) = ")); 234 Serial.println(data,HEX); 235 236 // default value 88 237 data = ReadRegisterValue(COM13); 238 Serial.print(F("COM13 (YUV Order - Lower Bit, Bit[1]) = ")); 239 Serial.println(data,HEX); 240 241 data = ReadRegisterValue(COM17); 242 Serial.print(F("COM17 (DSP Color Bar Selection) = ")); 243 Serial.println(data,HEX); 244 245 data = ReadRegisterValue(COM4); 246 Serial.print(F("COM4 (works with COM 17) = ")); 247 Serial.println(data,HEX); 248 249 data = ReadRegisterValue(COM15); 250 Serial.print(F("COM15 (COLOR FORMAT SELECTION) = "