mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
+ initial version
This commit is contained in:
parent
df54800ca6
commit
4592f98a04
56
libraries/ParPrinter/ParPrinter.cpp
Normal file
56
libraries/ParPrinter/ParPrinter.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// FILE: parprinter.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// PURPOSE: parallel printer class that implements the Print interface
|
||||
// DATE: 2013-09-30
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "ParPrinter.h"
|
||||
|
||||
ParPrinter::ParPrinter()
|
||||
{
|
||||
// define pins
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
pin[i] = 2+i;
|
||||
}
|
||||
}
|
||||
|
||||
void ParPrinter::begin()
|
||||
{
|
||||
pinMode(BUSY, INPUT);
|
||||
pinMode(STROBE, OUTPUT);
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
pinMode(pin[i], OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
// write() must implement the virtual write of the Print class
|
||||
size_t ParPrinter::write(uint8_t data)
|
||||
{
|
||||
while(digitalRead(BUSY) == HIGH);
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
digitalWrite(pin[i], bitRead(data, i) ); // direct port access will be faster
|
||||
}
|
||||
digitalWrite(STROBE, LOW);
|
||||
delay(2); // main time consuming part, so max 500chars/second = 10 lines.
|
||||
digitalWrite(STROBE, HIGH);
|
||||
while (digitalRead(BUSY) == HIGH);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
derive CLass HP: ParPrinter
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
// -- END OF FILE --
|
41
libraries/ParPrinter/ParPrinter.h
Normal file
41
libraries/ParPrinter/ParPrinter.h
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// FILE: ParPrinter.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// PURPOSE: parallel printer class that implements the Print interface
|
||||
// DATE: 2013-09-30
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#ifndef ParPrinter_h
|
||||
#define ParPrinter_h
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define PARPRINTER_VERSION "0.1.00"
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
// constant pin numbers
|
||||
#define STROBE 13 // same as build in LED ! makes it visible
|
||||
#define BUSY 2
|
||||
#define OUT_OF_PAPER 12
|
||||
|
||||
class ParPrinter: public Print
|
||||
{
|
||||
public:
|
||||
ParPrinter(); // lets assume fixed pins for now,
|
||||
void begin();
|
||||
size_t write(uint8_t);
|
||||
|
||||
private:
|
||||
uint8_t pin[8];
|
||||
};
|
||||
#endif
|
||||
// -- END OF FILE --
|
Loading…
Reference in New Issue
Block a user