def main():

  lcd = display_ssd1306_i2c.Display()

  sd = sdread.init_SD()
  sdread.mount(sd)
  wav_list = sdread.get_wav_list(sd)
  index = 0
  last_index = -1
  play_status = 0

  while True:
    pass
    if Pin_up.value() == 0 :
      print("up")
      if index > 0:
        index -= 1
    if Pin_down.value() == 0 :
      print("down")
      if index < len(wav_list) - 1:
        index += 1
    if Pin_play.value() == 0 :
      print("play")
      play_status = 1

    if index is not last_index:
      music_list_show(lcd,wav_list,index)
      last_index = index
      
    time.sleep(0.5)
    
    if play_status == 1:
      test2.music(Pin_play,wav_list[index])
      play_status = 0
      time.sleep(0.5)
    

  
  
  sdread.umount()

  #test2.music()
  pass
    def __init__(self):
        #obj
        self.Lcd = display_ssd1306_i2c.Display()
        self.Audio = None
        self.SDcard = None
        self.SPI = None

        #GPIO
        self.Pin_up = Pin(39, Pin.IN, Pin.PULL_UP)
        self.Pin_down = Pin(36, Pin.IN, Pin.PULL_UP)
        self.Pin_play = Pin(35, Pin.IN, Pin.PULL_UP)
        self.bck_pin = Pin(26)
        self.ws_pin = Pin(25)
        self.sdout_pin = Pin(27)

        #var
        self.index = 0
        self.last_index = -1
        self.play_status = 0
        self.wav_list = None
        self.wav_name = None

        pass
Exemple #3
0
# ???
pir_delay = 1


def reset_pin(pin, duration_low = 0.05, duration_high = 0.05):
    pin.value(0)
    sleep(duration_low)
    pin.value(1)
    sleep(duration_high)


# init OLED -- reset maybe not needed?!
prst = machine.Pin(16, machine.Pin.OUT)
reset_pin(prst)

display = display_ssd1306_i2c.Display(width = oled_width, height = oled_height, scl_pin_id = scl_oled, sda_pin_id = sda_oled, freq = freq_oled)

display.show_text("Display working!", x = 0, y = 10)

for k in range(3):
    i = 3-k
    display.show_text("starting test in", x = 0, y = 30, clear_first=False)
    display.show_text(str(i), x = k*10, y = 50, clear_first=False)
    sleep(1)

# init i2c
i2c = machine.I2C(scl = scl_i2c, sda = sda_i2c, freq=freq_i2c)
i2c_devices = i2c.scan()

# test
display.show_text("I2C Devices", x = 0, y = 5, clear_first=True)
            pass
    print('Network configuration:', sta_if.ifconfig())

wait_for_wifi()


# Signal boot successfully ___________
import led
led.blink_on_board_led(times = 2)



# Display ____________________________

import display_ssd1306_i2c as display
display = display.Display(width = 128, height = 32)
import ntp_clock 
ntp_clock.Clock(display).run()

# import wf8266kd
# display = wf8266kd.WF8266KD()
# import ntp_clock 
# ntp_clock.Clock(display).run()

# import wf8266t 
# display = wf8266t.WF8266T() 
# import ntp_clock 
# ntp_clock.Clock(display, buzzer = display.buzzer).run()

# import max_matrices
# display = max_matrices.Matrices()
Exemple #5
0
def blink(pin_id, low_seconds=0.05, high_seconds=0.05):
    pin = Pin(pin_id, Pin.OUT)
    pin.value(0)
    sleep(low_seconds)
    pin.value(1)
    sleep(high_seconds)


print('EUI', get_eui())
blink(16)
Pin(15, Pin.OUT)

oled = display_ssd1306_i2c.Display(width=128,
                                   height=64,
                                   scl_pin_id=15,
                                   sda_pin_id=4,
                                   freq=400000)


def show_packet(payload_string, rssi=None):
    oled.clear()
    line_idx = 0
    if rssi:
        oled.show_text('RSSI: {}'.format(rssi),
                       x=0,
                       y=line_idx * 10,
                       clear_first=False,
                       show_now=False)
        line_idx += 1
    for line, x, y in _wrap(payload_string, start_line=line_idx):
def main():
  
    wind_txt = ["north","northeast","east","southeast","south","southwest","west","northwest"]
  
    print('LOG::This message is from main function')
    micropython.mem_info()
    
    lcd = display_ssd1306_i2c.Display()
    
    ip = webserver.connect()
    lcd.show_text_wrap(ip)
   
    print('LOG::WIFI connect over.')
    micropython.mem_info()
    
    while True:
      
      """
      try:
      """
      #request weather api
      url = "https://free-api.heweather.net/s6/weather/now?location=shenzhen&key=2d63e6d9a95c4e8f8d3f65d0b5bcdf7f&lang=en"
      print("Prepare to get API")
      res = urequests.get(url)
      html=res.text
      print(html)
      print("request over")
      

      
      #parse json from weather api
      str_weather = ""
      weather_json = ujson.loads(html)
        
      up_time = weather_json["HeWeather6"][0]["update"]["loc"]
      location = weather_json["HeWeather6"][0]["basic"]["location"]
      cond_code = weather_json["HeWeather6"][0]["now"]["cond_code"]
      cond_txt = weather_json["HeWeather6"][0]["now"]["cond_txt"]
      tmp = weather_json["HeWeather6"][0]["now"]["tmp"]
      wind_deg = weather_json["HeWeather6"][0]["now"]["wind_deg"]
      wind_spd = weather_json["HeWeather6"][0]["now"]["wind_spd"]
      wind_dir = wind_txt[int(int(wind_deg)/45)]
      
      print("Prepare to Show")
      lcd.clear()
      lcd.show_text(up_time,0,0,False,True)
      lcd.show_text(location,0,10,False,True)
      lcd.show_text(tmp +" centigrade",0,20,False,True)
      lcd.show_text(cond_txt,0,30,False,True)
      lcd.show_text(wind_dir + " wind",0,40,False,True)
      lcd.show_text(wind_spd + " km/h",0,50,False,True)
      
      #init i2s to output audio
      speaker = audio_set.audio()
      
      print("Prepare to Speak")
      str_weather = location + " is " + tmp + " cent grade"
      speaker.say_sentance(str_weather)
      time.sleep(2)   #wait speak over
      
      str_weather = "weather is " + cond_txt
      speaker.say_sentance(str_weather)
      time.sleep(2)   #wait speak over
  
      str_weather = "wind direction is " + wind_dir
      speaker.say_sentance(str_weather)
      time.sleep(2)   #wait speak over
      
      str_weather = "wind speed is " + wind_spd + " kilometers per hour "
      speaker.say_sentance(str_weather)
      time.sleep(2)   #wait speak over
      
      speaker.close()
      """
      except :
        print("ERROR")
        pass
        """
      
      gc.collect()
      
      time.sleep(5)