Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <digitalWriteFast.h>
- #define FASTADC 1
- // defines for setting and clearing register bits
- #ifndef cbi
- #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
- #endif
- #ifndef sbi
- #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
- #endif
- int CLK = 23; //Pin that sends impluse to TSL1401R's CLK pin.
- int SI = 22; //Pin that sends impluse to TSL1401R's SI pin.
- int Cam1Aout = A2; //Pin that receives impluse TSL1401R's analog output.
- int Cam2Aout = A1; //Pin that receives impluse TSL1401R's analog output.
- int Cam3Aout = A0; //Pin that receives impluse TSL1401R's analog output.
- int delayTime = 170;
- unsigned long runTime;
- int pixelsArray1[128]; //Array to hold the values of the individual pixles.
- int pixelsArray2[128]; //Array to hold the values of the individual pixles.
- int pixelsArray3[128]; //Array to hold the values of the individual pixles.
- void setup()
- {
- #if FASTADC
- // set prescale to 16
- sbi(ADCSRA,ADPS2) ;
- cbi(ADCSRA,ADPS1) ;
- cbi(ADCSRA,ADPS0) ;
- #endif
- pinModeFast(CLK,OUTPUT); //Setting the CLK pin to be used for output
- pinModeFast(SI,OUTPUT); //Setting the SI pin to be used for output
- pinMode(Cam1Aout,INPUT); //Setting the analog pin to be used for input
- pinMode(Cam2Aout,INPUT); //Setting the analog pin to be used for input
- pinMode(Cam3Aout,INPUT); //Setting the analog pin to be used for input
- Serial.begin(9600); //Setting the data transfer rate
- //Serial.begin(19200); //Setting the data transfer rate
- /*noInterrupts();
- CLKPR = _BV(CLKPCE); // enable change of the clock prescaler
- CLKPR = _BV(CLKPS0); // divide frequency by 2
- interrupts();*/
- }
- /************************************************************************/
- void loop()
- {
- timming();
- readPixels();
- outputPixels();
- programRunTime();
- }
- /************************************************************************/
- /*This function calculates the runtime of the program.*/
- void programRunTime()
- {
- //runTime = millis();
- Serial.print("Runtime: ");
- //prints delayTime since program started
- Serial.println(runTime);
- // wait a second so as not to send massive amounts of data
- delay(100);
- exit(0);
- }
- /************************************************************************/
- /*This method is called at the begining of each cycle to throw away the old image and
- start a new cycle. Notice that unlike the readPixels function it contains a 129th impulse.*/
- void timming()
- {
- //The timing for the impluses was found through direct experimentation.
- //(Meaing that I played around with different delayTimes until the code worked)
- digitalWriteFast(SI, HIGH);
- delayMicroseconds(delayTime/2);
- digitalWriteFast(CLK, HIGH);
- delayMicroseconds(delayTime/2);
- digitalWriteFast(SI, LOW);
- delayMicroseconds(delayTime/2);
- digitalWriteFast(CLK, LOW);
- delayMicroseconds(delayTime);
- for(int i = 0; i < 129; i++)
- {
- digitalWriteFast(CLK, HIGH);
- delayMicroseconds(delayTime);
- digitalWriteFast(CLK, LOW);
- delayMicroseconds(delayTime);
- }
- }
- /************************************************************************/
- //This method reads in the values of the pixels and stores them into pixlesArray
- void readPixels()
- {
- digitalWriteFast(SI, HIGH);
- delayMicroseconds(delayTime/2);
- digitalWriteFast(CLK, HIGH);
- delayMicroseconds(delayTime/2);
- digitalWriteFast(SI, LOW);
- delayMicroseconds(delayTime/2);
- digitalWriteFast(CLK, LOW);
- delayMicroseconds(delayTime);
- for(int i = 0; i < 128; i++)
- {
- digitalWriteFast(CLK, HIGH);
- pixelsArray1[i]=analogRead(Cam1Aout);
- pixelsArray2[i]=analogRead(Cam2Aout);
- pixelsArray3[i]=analogRead(Cam3Aout);
- delayMicroseconds(delayTime);
- digitalWriteFast(CLK, LOW);
- delayMicroseconds(delayTime);
- }
- digitalWriteFast(CLK, HIGH);
- delayMicroseconds(delayTime);
- digitalWriteFast(CLK, LOW);
- delayMicroseconds(delayTime);
- delayMicroseconds(20);
- runTime = millis();
- }
- /************************************************************************/
- //This method outputs the results that have been stored in pixelsArray[].
- void outputPixels()
- {
- Serial.print("Camera 1: ");
- for(int j = 0; j < 128; j++)
- {
- //Serial.print(j);
- //Serial.print("=");
- Serial.print(pixelsArray1[j]);
- Serial.print(", ");
- //delay(75); //This delay is not necessary for functionallity, but makes result output slower so they are easier to read.
- }
- Serial.println();
- Serial.print("Camera 2: ");
- for(int j = 0; j < 128; j++)
- {
- //Serial.print(j);
- //Serial.print("=");
- Serial.print(pixelsArray2[j]);
- Serial.print(", ");
- //delay(75); //This delay is not necessary for functionallity, but makes result output slower so they are easier to read.
- }
- Serial.println();
- Serial.print("Camera 3: ");
- for(int j = 0; j < 128; j++)
- {
- //Serial.print(j);
- //Serial.print("=");
- Serial.print(pixelsArray3[j]);
- Serial.print(", ");
- //delay(75); //This delay is not necessary for functionallity, but makes result output slower so they are easier to read.
- }
- Serial.println();
- }
- Camera 1: 334, 358, 401, 451, 494, 531, 553, 575, 594, 612, 624, 634, 643, 654, 663, 668, 675, 680, 684, 688, 690, 688, 676, 671, 691, 711, 724, 728, 734, 740, 748, 755, 763, 770, 776, 783, 788, 793, 799, 801, 804, 806, 807, 807, 812, 815, 815, 824, 835, 846, 865, 881, 895, 914, 931, 952, 966, 980, 986, 996, 1012, 1022, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1003, 1004, 964, 978, 944, 955, 916, 911, 878, 873, 844, 838, 807, 801, 774, 768, 743, 728, 703, 697, 668, 636, 615, 596, 568, 532, 499, 462, 425, 395, 355, 327, 302, 279, 292, 299,
- Camera 2: 342, 367, 395, 422, 446, 467, 487, 511, 536, 556, 578, 596, 612, 630, 647, 660, 671, 688, 700, 713, 726, 736, 742, 752, 760, 767, 771, 783, 788, 796, 801, 807, 809, 814, 814, 817, 819, 825, 824, 825, 824, 824, 822, 827, 824, 827, 825, 825, 823, 824, 822, 823, 819, 819, 816, 816, 817, 822, 824, 829, 831, 841, 847, 856, 864, 875, 882, 894, 904, 915, 920, 924, 925, 931, 927, 931, 944, 936, 945, 931, 927, 930, 940, 922, 910, 907, 908, 884, 864, 881, 863, 858, 820, 835, 814, 792, 775, 787, 755, 763, 748, 737, 723, 712, 697, 687, 670, 655, 639, 625, 608, 590, 572, 551, 534, 515, 499, 481, 465, 447, 430, 409, 390, 368, 348, 331, 335, 327,
- Camera 3: 393, 407, 423, 428, 447, 476, 493, 504, 523, 536, 543, 559, 572, 588, 610, 620, 628, 638, 647, 655, 659, 662, 671, 675, 684, 689, 674, 678, 691, 688, 685, 679, 675, 668, 665, 660, 655, 652, 649, 647, 647, 648, 646, 644, 637, 639, 638, 635, 639, 639, 647, 641, 639, 639, 638, 633, 632, 631, 630, 621, 617, 610, 606, 597, 600, 600, 606, 612, 623, 632, 643, 652, 666, 679, 692, 707, 728, 746, 760, 771, 778, 783, 792, 798, 803, 795, 796, 785, 769, 747, 743, 735, 719, 696, 689, 673, 671, 658, 647, 639, 632, 627, 622, 614, 602, 590, 581, 572, 563, 551, 541, 526, 515, 502, 491, 478, 467, 454, 441, 428, 414, 403, 390, 374, 361, 352, 323, 323,
- Runtime: 98
- Camera 1: 191, 186, 193, 201, 207, 214, 216, 217, 223, 225, 227, 229, 230, 231, 233, 234, 236, 236, 237, 237, 238, 237, 236, 236, 238, 241, 242, 243, 244, 246, 248, 248, 249, 251, 251, 252, 254, 254, 255, 255, 255, 255, 255, 255, 257, 257, 258, 259, 261, 263, 266, 268, 271, 274, 277, 280, 283, 286, 287, 289, 294, 294, 298, 297, 301, 302, 307, 310, 312, 312, 312, 313, 312, 316, 322, 327, 327, 326, 327, 327, 329, 331, 330, 331, 332, 331, 327, 330, 319, 317, 313, 311, 308, 304, 299, 297, 297, 294, 287, 286, 282, 279, 276, 272, 268, 265, 262, 259, 255, 249, 247, 242, 240, 233, 231, 226, 222, 216, 211, 206, 200, 195, 189, 184, 179, 176, 173, 192,
- Camera 2: 179, 182, 187, 189, 194, 195, 199, 203, 207, 207, 212, 216, 218, 219, 223, 224, 227, 229, 231, 232, 235, 236, 238, 238, 240, 240, 242, 242, 244, 245, 247, 247, 248, 248, 247, 248, 248, 249, 248, 249, 249, 249, 249, 250, 251, 249, 250, 250, 251, 250, 251, 249, 250, 249, 249, 249, 249, 250, 252, 251, 253, 254, 255, 255, 259, 259, 263, 263, 267, 267, 269, 270, 271, 271, 273, 273, 274, 275, 275, 275, 275, 275, 275, 275, 275, 272, 271, 269, 268, 265, 263, 260, 259, 257, 255, 253, 252, 248, 248, 244, 242, 241, 240, 236, 235, 231, 230, 227, 225, 223, 220, 216, 216, 211, 209, 205, 204, 199, 198, 195, 192, 188, 187, 183, 179, 176, 188, 215,
- Camera 3: 188, 190, 192, 193, 195, 199, 201, 202, 207, 209, 211, 213, 215, 214, 220, 222, 224, 224, 225, 224, 227, 229, 230, 230, 231, 231, 231, 231, 231, 231, 231, 231, 231, 229, 230, 228, 228, 227, 227, 227, 227, 228, 227, 226, 226, 226, 225, 225, 226, 226, 227, 226, 227, 226, 226, 226, 225, 225, 225, 224, 224, 223, 222, 220, 220, 220, 223, 223, 224, 226, 227, 230, 231, 235, 238, 240, 243, 248, 249, 252, 253, 255, 255, 258, 259, 259, 257, 255, 253, 249, 248, 246, 244, 241, 236, 236, 233, 231, 231, 231, 229, 227, 228, 227, 225, 224, 221, 220, 218, 216, 215, 212, 210, 207, 208, 204, 200, 199, 196, 196, 193, 191, 190, 188, 184, 184, 162, 187,
- Runtime: 19
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement