GY-63_MS5611/libraries/ParallelPrinter/examples/PrinterSimulator/PrinterSimulator.ino

69 lines
1.2 KiB
Arduino
Raw Normal View History

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