Esempio n. 1
0
 def set_px(self, x, y, color):
     page, shiftPage = divmod(y, 8)
     i = x + page * 128 + 1
     b = self.screen[i] | (
         1 << shiftPage) if color else self.screen[i] & ~(1 << shiftPage)
     self.screen[i] = b
     self.__set_pos(x, page)
     spi.write(bytearray([b]))
Esempio n. 2
0
def NFC_write_register(register, value):
    bregister = bytearray([register])
    bvalue = bytearray([value])
    CS_PIN.write_digital(0)
    spi.write(bregister)
    # need to think about writing a loop for multi byte write
    spi.write(bvalue)
    CS_PIN.write_digital(1)
Esempio n. 3
0
 def init(self): 
  #set buf with setup commands, turn on display, clear display and make ready for commands
  buf = bytearray([self.FUNCTION_SET1_CMD, self.DISPLAY_ON, self.CLEAR_DISPLAY, 0x06])
  #set the spi pins and frequency
  spi.init(baudrate=250000, bits=8, mode=0, sclk=pin13, mosi=pin15, miso=pin14)
  sleep(1000)
  #send setup to the LCD
  spi.write(buf)
  self.initalised = True
Esempio n. 4
0
def NFC_read_register(register):
    CS_PIN.write_digital(0)
    data = bytearray([0x80 | register])
    spi.write(data)
    # spi.write(0x00)#maybe?
    value = 0xff
    value = spi.read(1)
    CS_PIN.write_digital(1)
    return int(value[0])
 def displayStringOnLine(self, lcdLineAddr, text):  # display string on a selected line of the LCD
  textLoop = 0
  lengthOfText = len(text)
  #if the text is less than 16 charectors, fill the rest with white spaces
  if lengthOfText < 16:
     lcdLengthToAdd = 16 - lengthOfText
     for textLoop in range (0, lcdLengthToAdd):
      text = text + ' '
     textLoop = 0
  #Send command byte and set which line of the LCD is being written to
  buf = bytearray([self.FUNCTION_SET1_CMD, lcdLineAddr])
  spi.write(buf)
  #Send command byte and set how many bytes are being sent
  buf = bytearray([self.FUNCTION_SET2_CMD, 0x8F])
  spi.write(buf)
  #send all string letters into byte array as int to send all together
  buf = bytearray([ord(text[0]),ord(text[1]),ord(text[2]),ord(text[3]),ord(text[4]),ord(text[5]),ord(text[6]),ord(text[7]),ord(text[8]),ord(text[9]),ord(text[10]),ord(text[11]),ord(text[12]),ord(text[13]),ord(text[14]),ord(text[15])])
  #print(buf)
  spi.write(buf)
Esempio n. 6
0
 def displayStringOnLine(self, lcdLineAddr, text):  # display string on a selected line of the LCD
  textLoop = 0
  lengthOfText = len(text)
  #if the text is less than 16 charectors, fill the rest with white spaces
  if lengthOfText < 16:
     lcdLengthToAdd = 16 - lengthOfText
     for textLoop in range (0, lcdLengthToAdd):
      text = text + ' '
     textLoop = 0
  #Send command byte and set which line of the LCD is being written to
  buf = bytearray([self.FUNCTION_SET1_CMD, lcdLineAddr])
  spi.write(buf)
  #Send command byte and set how many bytes are being sent
  buf = bytearray([self.FUNCTION_SET2_CMD, 0x8F])
  spi.write(buf)
  #send the display bytes to the LCD
  for textLoop in range (16):
   asciiNumber = text[textLoop]
   buf = bytearray([ord(asciiNumber)])
   spi.write(buf)
Esempio n. 7
0
 def show_bitmap(self, filename):
     self.__set_pos()
     with open(filename, 'rb') as my_file:
         for i in range(0, 16):
             spi.write(my_file.read(64))
Esempio n. 8
0
 def __cmd(self, c):
     pin16.write_digital(0)
     spi.write(bytearray(c))
     pin16.write_digital(1)
Esempio n. 9
0
 def draw_screen(self):
     self.__set_pos()
     spi.write(self.screen)