This repository has been archived on 2024-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
ParallelPrinter/examples/PrinterSimulator/PrinterSimulator.ino

69 lines
1.2 KiB
Arduino
Raw Normal View History

2020-06-25 08:19:33 +00:00
//
// FILE: PrinterSimulator.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2020-06-24
//
2020-06-25 08:19:33 +00:00
// Simple parallel printer simulator, prints to serial...
// version could be made with a shiftin register ....
2020-06-25 08:19:33 +00:00
#include "Arduino.h"
uint8_t PIN_STROBE = 2;
uint8_t PIN_BUSY = 13;
uint8_t PIN_OOP = 10;
2020-06-25 08:19:33 +00:00
uint8_t dataPins[] = { 3, 4, 5, 6, 7, 8, 9, 10 };
2020-06-25 08:19:33 +00:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
pinMode(PIN_STROBE, INPUT);
pinMode(PIN_OOP, OUTPUT);
pinMode(PIN_BUSY, OUTPUT); // build in LED UNO.
2020-06-25 08:19:33 +00:00
for (uint8_t i = 0; i < 8; i++)
{
pinMode(dataPins[i], INPUT);
}
digitalWrite(PIN_OOP, HIGH); // HIGH is OK
digitalWrite(PIN_BUSY, HIGH); // BUSY during startup
2020-06-25 08:19:33 +00:00
delay(5000); // do startup thingies.
}
2020-06-25 08:19:33 +00:00
void loop()
{
handleInput();
// do other things here
}
2020-06-25 08:19:33 +00:00
void handleInput()
{
uint8_t x = 0;
digitalWrite(PIN_BUSY, LOW);
while (digitalRead(PIN_STROBE) == HIGH) yield();
2020-06-25 08:19:33 +00:00
for (int i = 0; i < 8; i++)
{
x <<= 1;
if (digitalRead(dataPins[i]) == HIGH) x += 1;
}
while (digitalRead(PIN_STROBE) == LOW) yield();
digitalWrite(PIN_BUSY, HIGH);
2020-06-25 08:19:33 +00:00
// process data
Serial.write(x);
}
2020-06-25 08:19:33 +00:00
// -- END OF FILE --