Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*------------------------------------------------------------------------
  2.   Example sketch for Adafruit Thermal Printer library for Arduino.
  3.   Demonstrates a few text styles & layouts, bitmap printing, etc.
  4.  
  5.   IMPORTANT: DECLARATIONS DIFFER FROM PRIOR VERSIONS OF THIS LIBRARY.
  6.   This is to support newer & more board types, especially ones that don't
  7.   support SoftwareSerial (e.g. Arduino Due).  You can pass any Stream
  8.   (e.g. Serial1) to the printer constructor.  See notes below.
  9.  
  10.   You may need to edit the PRINTER_FIRMWARE value in Adafruit_Thermal.h
  11.   to match your printer (hold feed button on powerup for test page).
  12.   ------------------------------------------------------------------------*/
  13.  
  14. #include "Adafruit_Thermal.h"
  15. #include "adalogo.h"
  16. #include "adaqrcode.h"
  17.  
  18. // Here's the new syntax when using SoftwareSerial (e.g. Arduino Uno) ----
  19. // If using hardware serial instead, comment out or remove these lines:
  20.  
  21. //#include "SoftwareSerial.h"
  22. //#define TX_PIN 6 // Arduino transmit  YELLOW WIRE  labeled RX on printer
  23. //#define RX_PIN 5 // Arduino receive   GREEN WIRE   labeled TX on printer
  24.  
  25. //SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
  26. Adafruit_Thermal printer(&Serial);     // Pass addr to printer constructor
  27. // Then see setup() function regarding serial & printer begin() calls.
  28.  
  29. // Here's the syntax for hardware serial (e.g. Arduino Due) --------------
  30. // Un-comment the following line if using hardware serial:
  31.  
  32. //Adafruit_Thermal printer(&Serial1);      // Or Serial2, Serial3, etc.
  33.  
  34. // -----------------------------------------------------------------------
  35.  
  36. void setup() {
  37.  
  38.   // This line is for compatibility with the Adafruit IotP project pack,
  39.   // which uses pin 7 as a spare grounding point.  You only need this if
  40.   // wired up the same way (w/3-pin header into pins 5/6/7):
  41.   pinMode(7, OUTPUT); digitalWrite(7, LOW);
  42.  
  43.   // NOTE: SOME PRINTERS NEED 9600 BAUD instead of 19200, check test page.
  44.   Serial1.begin(9600);  // Initialize SoftwareSerial
  45.   //Serial1.begin(19200); // Use this instead if using hardware serial
  46.   printer.begin();        // Init printer (same regardless of serial type)
  47.  
  48.   // The following calls are in setup(), but don't *need* to be.  Use them
  49.   // anywhere!  They're just here so they run one time and are not printed
  50.   // over and over (which would happen if they were in loop() instead).
  51.   // Some functions will feed a line when called, this is normal.
  52.  
  53.   // Test inverse on & off
  54.   printer.inverseOn();
  55.   printer.println(F("Inverse ON"));
  56.   printer.inverseOff();
  57.  
  58.   // Test character double-height on & off
  59.   printer.doubleHeightOn();
  60.   printer.println(F("Double Height ON"));
  61.   printer.doubleHeightOff();
  62.  
  63.   // Set text justification (right, center, left) -- accepts 'L', 'C', 'R'
  64.   printer.justify('R');
  65.   printer.println(F("Right justified"));
  66.   printer.justify('C');
  67.   printer.println(F("Center justified"));
  68.   printer.justify('L');
  69.   printer.println(F("Left justified"));
  70.  
  71.   // Test more styles
  72.   printer.boldOn();
  73.   printer.println(F("Bold text"));
  74.   printer.boldOff();
  75.  
  76.   printer.underlineOn();
  77.   printer.println(F("Underlined text"));
  78.   printer.underlineOff();
  79.  
  80.   printer.setSize('L');        // Set type size, accepts 'S', 'M', 'L'
  81.   printer.println(F("Large"));
  82.   printer.setSize('M');
  83.   printer.println(F("Medium"));
  84.   printer.setSize('S');
  85.   printer.println(F("Small"));
  86.  
  87.   printer.justify('C');
  88.   printer.println(F("normal\nline\nspacing"));
  89.   printer.setLineHeight(50);
  90.   printer.println(F("Taller\nline\nspacing"));
  91.   printer.setLineHeight(); // Reset to default
  92.   printer.justify('L');
  93.  
  94.   // Barcode examples:
  95.   // CODE39 is the most common alphanumeric barcode:
  96.   printer.printBarcode("ADAFRUT", CODE39);
  97.   printer.setBarcodeHeight(100);
  98.   // Print UPC line on product barcodes:
  99.   printer.printBarcode("123456789123", UPC_A);
  100.  
  101.   // Print the 75x75 pixel logo in adalogo.h:
  102.   printer.printBitmap(adalogo_width, adalogo_height, adalogo_data);
  103.  
  104.   // Print the 135x135 pixel QR code in adaqrcode.h:
  105.   printer.printBitmap(adaqrcode_width, adaqrcode_height, adaqrcode_data);
  106.   printer.println(F("Adafruit!"));
  107.   printer.feed(2);
  108.  
  109.   printer.sleep();      // Tell printer to sleep
  110.   delay(3000L);         // Sleep for 3 seconds
  111.   printer.wake();       // MUST wake() before printing again, even if reset
  112.   printer.setDefault(); // Restore printer to defaults
  113. }
  114.  
  115. void loop() {
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement