hi! i got completely lost on how to do this, since the strategy i thought would work, didn't. I hav an attiny that writtes a byte to a cable on button press. now i need to read that byte with the arduino. i made a while loopwith a digital read function that supposedly recollected and joined again the byte, adding a delay to sync the 8mhz tiny's clock with the arduino uno's clock. the thing is that i got just nonesense bytes, seems that the reading loop goes slower than the tiny's writing.
then, how can i read a supposed 8mhz clock's serial with the arduino?
this is the attiny's code; supposedly writes his "me" byte at 8mhz (see the part with many****).
// reset -1 8- VCC+
// (analog input 3) pin3 -2 7- pin2 (Analog input 1, SCK)
// (analog input 2) pin4 -3 6- pin1 (PWM, MISO)
// GND -4 5- Pin0 (PWM, AREF, MOSI)
//este incremental fue realizado fuera de contaxto para probar al día 10/10/12
int ledPin = 0;
int triggeri=4;
int triggero= 2;
int colectorpin = 3;
int debugpin=1;
int previoustriggerinput=0;
int trigando=0;
int indispuesto=0;
byte me=10101011;
int repeatplease = 2;
int statePin = LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(triggeri, INPUT);
pinMode(triggero, OUTPUT);
pinMode(colectorpin, INPUT);
pinMode(debugpin, OUTPUT);
}
void loop() {
if (digitalRead(triggeri)>previoustriggerinput){//trigger
trigando=1000;
pinMode(colectorpin, INPUT);
if(digitalRead(colectorpin)){//if it reads something in its output, wait 8
indispuesto=9;
}
pinMode(colectorpin, OUTPUT);
if(indispuesto<1){
indispuesto--;
int B=0;
while(repeatplease>B) //here the byte is written*************************************************
{
int C=0;
while(C<9){
digitalWrite(colectorpin,bitRead(me,C));
C++;
}
//triggering=triggertime*2;
B++;
}
}
}
if(statePin==HIGH){
statePin=LOW;
}
else{
statePin=HIGH;
}
digitalWrite(debugpin, statePin);
if(trigando>5000){
digitalWrite(triggero, LOW);//over 300, off
digitalWrite(ledPin, HIGH);
trigando-=1;
}
else if(trigando>5){
digitalWrite(triggero, HIGH);//between 300 and 1, on
trigando-=1;
}
else{
digitalWrite(triggero, LOW);//at0, off
digitalWrite(ledPin, LOW);
}
previoustriggerinput=analogRead(triggeri);
}
does anyone has experience with something like this? how could this be done? why do i get nonesense readings?
thanks!