Advertisement
Guest User

Untitled

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