Skip to content

Instantly share code, notes, and snippets.

@robseward
Last active February 7, 2016 22:12
Show Gist options
  • Save robseward/9dc45f50f2e3127c9811 to your computer and use it in GitHub Desktop.
Save robseward/9dc45f50f2e3127c9811 to your computer and use it in GitHub Desktop.
/**
* Z1FFER v0.3.X Firmware.
*
* This code is designed to be as fast as possible.
* It operates two inverted clock signals on pins 9 and 10
* while reading in random bytes on pins 6 and 7.
* Pins are read and written to using the registers for speed.
* The clock signal is irregular but this does not effect the
* performance of the ZIFFER shield.
*/
bool flip = false;
void setup() {
//Set B pins to output
DDRB = 0b11111111;
//Set D pins to input
DDRD = 0x00;
//Baud rate of 2000000 is around the theoretical maximum of an Ardunio Uno r3
Serial.begin(2000000);
}
int currentByte = 0;
int i=0;
void loop() {
currentByte = 0;
for (i=0; i < 8; i += 2) {
runClockSignals();
runClockSignals();
byte pinVal = (PIND >> 6) & B00000011;
currentByte |= pinVal << i;
}
Serial.write(currentByte);
}
void runClockSignals(){
if (flip) {
PORTB = 0b00000010;
}
else {
PORTB = 0b00000100;
}
flip = !flip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment