// 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 #define F_CPU 16000000UL //#define ARRAY 128 //uint8_t CLKcycleCounter = 0; // counts the number of clock cycles expired #define CLK 5 // Clock pin (TIMER2 will need changing if you move this pin. PD5) #define SI 4 // SI pin PD4) #define LED 13 // Pin PB5 int analogPin = A0; // PinA0 int Array[128]; void setup() { DDRD=0xFF; Serial.begin(9600); sbi(CLKPR,CLKPS0); //Clock Prescaler:8 sbi(CLKPR,CLKPS1); cbi(CLKPR,CLKPS2); cbi(CLKPR,CLKPS3); //ADC Prescaler:16 cbi(ADCSRA,ADPS0); cbi(ADCSRA,ADPS1); sbi(ADCSRA,ADPS2); } void SI_Pulse() { digitalWrite(SI,HIGH); //Set SI high delayMicroseconds(100); //Stay high for a duration digitalWrite(SI,LOW); //Set SI low } void CLK_Pulse() { digitalWrite(CLK,HIGH); //Set Clock high delayMicroseconds(100); //Stay high for a duration digitalWrite(CLK,LOW); //Set Clock low } void loop() { delay(1000); for(int i=0; i<128;i++) //for 128 Cycles Generate Clock and SI { CLK_Pulse(); //Set Clock Pulse if(i == 0) // During the first pulse { SI_Pulse(); //Set SI function } else if(i != 0) { digitalWrite(SI,LOW); //Set SI complete Low } delayMicroseconds(1000); int Pixel=analogRead(A0); //Reading Analog Data if(Pixel>100) //100 is just an example value between 0-1023 { Array[i]=Pixel; } else if(Pixel<=100) { Array[i]=0; } } for(int j=0; j<128;j++) { Serial.print(Array[j]); } delay(10); //delay time for integration }