mirror of
https://github.com/m5stack/M5Cloud.git
synced 2026-05-20 10:07:21 -07:00
add BTC Ticker example
This commit is contained in:
@@ -227,6 +227,24 @@ Set characteristics of the 7-segment font
|
||||
Return width and height of the active font
|
||||
|
||||
|
||||
### lcd.print(text[, x, y, color, rotate, transparent, fixedwidth, wrap])
|
||||
|
||||
Display the string *text* at possition (x,y).<br>
|
||||
If *color* is not given, current foreground color is used.
|
||||
|
||||
* **x**: horizontal position of the upper left point in pixels, special values can be given:
|
||||
* CENTER, centers the text
|
||||
* RIGHT, right justifies the text
|
||||
* LASTX, continues from last X position; offset can be used: LASTX+n
|
||||
* **y**: vertical position of the upper left point in pixels, special values can be given:
|
||||
* CENTER, centers the text
|
||||
* BOTTOM, bottom justifies the text
|
||||
* LASTY, continues from last Y position; offset can be used: LASTY+n
|
||||
* **text**: string to be displayed. Two special characters are allowed in strings:
|
||||
* ‘\r’ CR (0x0D), clears the display to EOL
|
||||
* ‘\n’ LF (ox0A), continues to the new line, x=0
|
||||
|
||||
|
||||
### lcd.text(x, y, text [, color])
|
||||
|
||||
Display the string *text* at possition (x,y).<br>
|
||||
@@ -241,8 +259,8 @@ If *color* is not given, current foreground color is used.
|
||||
* BOTTOM, bottom justifies the text
|
||||
* LASTY, continues from last Y position; offset can be used: LASTY+n
|
||||
* **text**: string to be displayed. Two special characters are allowed in strings:
|
||||
* ‘\r’ CR (0x0D), clears the display to EOL
|
||||
* ‘\n’ LF (ox0A), continues to the new line, x=0
|
||||
* ‘\r’ CR (0x0D), clears the display to EOL
|
||||
* ‘\n’ LF (ox0A), continues to the new line, x=0
|
||||
|
||||
|
||||
### lcd.textWidth(text)
|
||||
|
||||
-364
@@ -1,364 +0,0 @@
|
||||
# M5Stack Web IDE
|
||||
|
||||
[EN](#alios-things) | [中文](#alios-things概述)
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 烧录固件
|
||||
|
||||
#### MacOS/Linux烧录
|
||||
- 使用pip安装esptool:
|
||||
|
||||
```pip install esptool```
|
||||
- 先擦除:
|
||||
``` esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART erase_flash ```
|
||||
- 烧录bin文件:
|
||||
``` esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART write_flash -z 0x1000 firmware.bin ```
|
||||
|
||||
|
||||
#### Windows烧录
|
||||
Windows使用Espressif提供Flash Download Tools工具烧录([点击下载](http://espressif.com/sites/default/files/tools/flash_download_tools_v3.6.2.2_0.rar)),设置如下(先擦除再烧录):
|
||||

|
||||
|
||||
|
||||
### 2. 让设备WiFi接入网络
|
||||
- **方法1:** 使用热点接入,通过Web配置网络
|
||||
- 手机或电脑连接M5Stack Core屏幕提示的WiFi热点
|
||||

|
||||
|
||||
连接M5Stack Core WiFi:
|
||||
|
||||

|
||||
- 打开浏览器登陆 192.168.4.1填入WiFi的SSID和密码
|
||||

|
||||
|
||||
- **方法2:** 通过串口配置WiFi密码
|
||||
|
||||
通过串口REPL或者上传工具在设备根目录下创建一个名字为:config.json的文件,文件内wifi的配置参数JSON格式如下:
|
||||
```
|
||||
{
|
||||
"wifi":{
|
||||
"ssid":"MasterHax_2.4G",
|
||||
"password":"12345678"
|
||||
}
|
||||
}
|
||||
```
|
||||
- **方法3:** 通过微信扫描二维码Airkiss接入
|
||||
|
||||
TODO
|
||||
|
||||
### 3. 绑定设备
|
||||
登陆 http://io.m5cloud.com 注册账号,添加设备:
|
||||
|
||||

|
||||
|
||||
将M5Stack Core屏幕显示的Check Code填入绑定设备,Check Code是一次性随机的,60秒会刷新一次,仅仅用于设备绑定验证。
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
### 4. 开始编程
|
||||

|
||||
|
||||
# **M5Stack** Micropython
|
||||
|
||||
Micropython 快速入门
|
||||
|
||||
## **LCD**
|
||||
|
||||
---
|
||||
|
||||
在使用LCD前,先导入LCD对象:
|
||||
|
||||
```python
|
||||
from m5stack import lcd
|
||||
lcd.print('hello world!')
|
||||
```
|
||||
|
||||
也可以直接这样:
|
||||
|
||||
```python
|
||||
import m5stack
|
||||
m5stack.lcd.print('hello world!')
|
||||
```
|
||||
|
||||
或者这样:
|
||||
|
||||
```python
|
||||
import m5stack
|
||||
lcd = m5stack.lcd
|
||||
lcd.print('hello world!')
|
||||
```
|
||||
|
||||
|
||||
#### 颜色
|
||||
|
||||
LCD的 **Color** 颜色使用**24bit**整数类型表示,RGB对应各8bit。
|
||||
|
||||
比如: **0xFF0000** 相当于于完全红色,**0x00FF00** 相当于原谅色绿色。
|
||||
|
||||
常用的颜色可以直接用定义到的参数:
|
||||
|
||||
**BLACK, NAVY, DARKGREEN, DARKCYAN, MAROON, PURPLE, OLIVE, LIGHTGREY, DARKGREY, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE, ORANGE, GREENYELLOW, PINK**
|
||||
|
||||
比如想在LCD打印一句绿色的hello world可以这样:
|
||||
```python
|
||||
lcd.print('hello world', color=lcd.GREEN)
|
||||
```
|
||||
|
||||
也可以这样:
|
||||
```python
|
||||
lcd.print('hello world', color=0X00FF00)
|
||||
```
|
||||
|
||||
### lcd.setColor(color [,bcolor])
|
||||
设置默认的绘画颜色和背景色,bcolor一般用于设置文字显示的背景色。
|
||||
|
||||
|
||||
### lcd.print(text, [x, y, color])
|
||||
|
||||
显示字符串 *text* 在 *(x, y)* 指定的位置,参数 *color* 为颜色参数。
|
||||
|
||||
(注:在中括号如[x, y, color]内的表示为可选参数)
|
||||
|
||||
* **x**: 指定水平方向的位置显示, 有以下特殊参数:
|
||||
* LASTX(默认), 直接上一个光标的文字接着显示
|
||||
* CENTER, 居中显示文本
|
||||
* RIGHT, 右对齐文本
|
||||
|
||||
* **y**: 指定垂直方向的位置显示, 有以下特殊参数:
|
||||
* LASTX(默认), 直接上一个光标的文字接着显示
|
||||
* CENTER, 居中显示文本
|
||||
* BOTTOM, 文字靠底部显示
|
||||
|
||||
* **color**:如果该参数未设置,默认为 *lcd.setColor* 设置的颜色。
|
||||
|
||||
|
||||
|
||||
### lcd.println(text, [x, y, color])
|
||||
|
||||
lcd.println函数功能与 *lcd.print* 函数功能基本一样,只是会在最后自动换行。
|
||||
|
||||
```python
|
||||
lcd.print('hello world\n')
|
||||
lcd.println('hello world') #显示效果一致
|
||||
```
|
||||
|
||||
|
||||
### lcd.font(font)
|
||||
|
||||
设置字体.
|
||||
|
||||
可以使用内置的字体已定义好的参数:
|
||||
|
||||
**FONT_Default, FONT_DefaultSmall, FONT_DejaVu18, FONT_Dejavu24, FONT_Ubuntu, FONT_Comic, FONT_Minya, FONT_Tooney, FONT_Small, FONT_7seg**
|
||||
|
||||
```python
|
||||
lcd.font(lcd.FONT_Dejavu24) #设置为FONT_Dejavu24字体
|
||||
```
|
||||
|
||||
### lcd.textWidth(text)
|
||||
|
||||
返回字符串 *text* 字体显示占用的宽度。
|
||||
|
||||
|
||||
### lcd.fontSize()
|
||||
|
||||
返回当前字体的 *width* 和 *heigh*。
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
from m5stack import lcd
|
||||
|
||||
#在屏幕上hello world
|
||||
lcd.print('hello world')
|
||||
|
||||
#在屏幕x=10,y=100的地方显示hello world
|
||||
lcd.print('hello world', 10, 100)
|
||||
|
||||
#显示的文字颜色为绿色的hello world
|
||||
lcd.print('hello wrold', color=0xFF0000)
|
||||
|
||||
#在屏幕x=10,y=100的地方显示红色的hello world字体
|
||||
lcd.print('hello world', 10, 200, 0xFF0000)
|
||||
|
||||
#设置字体为FONT_Dejavu24
|
||||
lcd.font(lcd.FONT_Dejavu24)
|
||||
lcd.println('hello world')
|
||||
```
|
||||
|
||||
|
||||
### lcd.pixel(x, y [,color])
|
||||
|
||||
画一个像素点在指定位置 (x,y). 如果 *color* 参数未设置, 则默认使用 *lcd.setColor* 设置的前景色.
|
||||
|
||||
### lcd.line(x, y, x1, y1 [,color])
|
||||
|
||||
画一条直线从坐标(x,y) 到 (x1,y1). 画一个像素点在指定位置 (x,y). 如果 *color* 参数未设置, 则默认使用 *lcd.setColor* 设置的前景色.
|
||||
|
||||
|
||||
### lcd.rect(x, y, width, height, [color, fillcolor])
|
||||
|
||||
画一个矩形,(x,y)为矩形左上角的起始坐标,参数 *width* 和 *height* 为设置矩形的宽度和高度。
|
||||
|
||||
如果 *color* 和 参数未设置, 则默认使用 *lcd.setColor* 设置的前景色.
|
||||
|
||||
可选参数 *fillcolor* 为矩形的填充色。
|
||||
|
||||
```python
|
||||
lcd.rect(10, 100, 100, 200, 0xFF0000) #不填充颜色
|
||||
lcd.rect(10, 100, 100, 200, 0xFF0000, 0x00FF00) #填充矩形内部为绿色
|
||||
```
|
||||
|
||||
### lcd.triangle(x, y, x1, y1, x2, y2 [,color, fillcolor])
|
||||
|
||||
画一个三角形根据指定的三个点 (x,y), (x1,y1) and (x2,y2).
|
||||
|
||||
|
||||
### lcd.circle(x, y, r [,color, fillcolor])
|
||||
|
||||
画一个圆,参数(x,y)为圆的原点,*r* 为半径.
|
||||
|
||||
|
||||
### lcd.ellipse(x, y, rx, ry [opt, color, fillcolor])
|
||||
|
||||
画一个椭圆 (x,y)和 (rx, ry) 为椭圆的两个焦点.
|
||||
|
||||
**opt* 参数用于显示象限, 默认是 15, 显示整个椭圆.
|
||||
|
||||
Multiple segments can drawn, combine (logical or) the values.
|
||||
* 1 - upper left segment
|
||||
* 2 - upper right segment
|
||||
* 4 - lower left segment
|
||||
* 8 - lower right segment
|
||||
|
||||
If *fillcolor* is given, filled elipse will be drawn.
|
||||
|
||||
|
||||
### lcd.arc(x, y, r, thick, start, end [color, fillcolor])
|
||||
|
||||
画一个圆弧中心点 (x,y), *r* 为半径,*thick* 为边的厚度,起始角度 *start* 和 *end* 角度(0~360度)。
|
||||
|
||||
|
||||
### lcd.polygon(x, y, r, sides, thick, [color, fillcolor, rotate])
|
||||
|
||||
画一个多边形中心点 (x,y), *r* 为半径, 参数 *sides* 为多边形的边数,*thick* 为边的厚度。
|
||||
|
||||
如果设置了 *rotate* 参数, 可以旋转多边形的角度 (0~359)
|
||||
|
||||
|
||||
### lcd.roundrect(x, y, width, height, r [color, fillcolor])
|
||||
|
||||
圆角矩形参数 *r* 为圆角的半径.
|
||||
|
||||
|
||||
### lcd.clear([color])
|
||||
|
||||
等价于lcd.fill([color])
|
||||
|
||||
Clear the screen with default background color or specific color if given.
|
||||
|
||||
清除屏幕显示的内容,填充指定的颜色,默认是 *lcd.setColor* 设置的背景色。
|
||||
|
||||
|
||||
### lcd.image(x, y, file [,scale, type])
|
||||
|
||||
显示图片*file*,(x,y)为起始位置
|
||||
* 支持 **JPG** and **BMP** 图片格式.
|
||||
* Constants **lcd.CENTER**, **lcd.BOTTOM**, **lcd.RIGHT** can be used for x&y
|
||||
* **x** and **y** values can be negative
|
||||
|
||||
**scale**: 图片缩放比例
|
||||
|
||||
**type**: 图片的类型 *lcd.JPG* 或 *lcd.BMP*
|
||||
|
||||
## **Button**
|
||||
|
||||
---
|
||||
```python
|
||||
import m5stack as m5
|
||||
|
||||
def press_cb(pin):
|
||||
m5.lcd.println('button_press A')
|
||||
print('button_press A')
|
||||
|
||||
m5.BtnA.set_callback(press_cb)
|
||||
```
|
||||
|
||||
或者:
|
||||
|
||||
```python
|
||||
import m5stack as m5
|
||||
|
||||
while True:
|
||||
if m5.BtnA.press():
|
||||
m5.lcd.println('button_press A')
|
||||
time.sleep_ms(10)
|
||||
|
||||
```
|
||||
|
||||
|
||||
## **SD Card**
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
import uos
|
||||
|
||||
uos.mountsd()
|
||||
uos.listdir('/sd')
|
||||
```
|
||||
|
||||
|
||||
## **Beep**
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
import m5stack as m5
|
||||
|
||||
m5.beep.tone(freq=1800)
|
||||
m5.beep.tone(freq=1800, timeout=200)
|
||||
```
|
||||
|
||||
## **GPIO**
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
import machine
|
||||
|
||||
pinout = machine.Pin(0, machine.Pin.OUT)
|
||||
pinout.value(1)
|
||||
|
||||
pinin = machine.Pin(2, machine.Pin.IN)
|
||||
val = pinin.value()
|
||||
```
|
||||
|
||||
## **PWM**
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
import machine
|
||||
|
||||
pwm = machine.PWM(machine.Pin(3))
|
||||
pwm.freq(5000)
|
||||
pwm.duty(666)
|
||||
```
|
||||
|
||||
|
||||
## **ADC**
|
||||
|
||||
---
|
||||
```python
|
||||
import machine
|
||||
|
||||
adc = machine.ADC(35)
|
||||
adc.read()
|
||||
```
|
||||
@@ -1,299 +0,0 @@
|
||||
# **M5Stack** Micropython
|
||||
|
||||
Micropython 快速入门
|
||||
|
||||
## **LCD**
|
||||
|
||||
---
|
||||
|
||||
在使用LCD前,先导入LCD对象:
|
||||
|
||||
```python
|
||||
from m5stack import lcd
|
||||
lcd.print('hello world!')
|
||||
```
|
||||
|
||||
也可以直接这样:
|
||||
|
||||
```python
|
||||
import m5stack
|
||||
m5stack.lcd.print('hello world!')
|
||||
```
|
||||
|
||||
或者这样:
|
||||
|
||||
```python
|
||||
import m5stack
|
||||
lcd = m5stack.lcd
|
||||
lcd.print('hello world!')
|
||||
```
|
||||
|
||||
|
||||
#### 颜色
|
||||
|
||||
LCD的**Color** 颜色使用 **24bit** 整数类型表示,RGB对应各8bit。
|
||||
|
||||
比如: **0xFF0000** 相遇于完全红色,**0x00FF00** 相遇于原谅色绿色。
|
||||
|
||||
常用的颜色可以直接用定义到的参数:
|
||||
|
||||
**BLACK, NAVY, DARKGREEN, DARKCYAN, MAROON, PURPLE, OLIVE, LIGHTGREY, DARKGREY, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE, ORANGE, GREENYELLOW, PINK**
|
||||
|
||||
比如想在LCD打印一句绿色的hello world可以这样:
|
||||
```python
|
||||
lcd.print('hello world', color=lcd.GREEN)
|
||||
```
|
||||
|
||||
也可以这样:
|
||||
```python
|
||||
lcd.print('hello world', color=0X00FF00)
|
||||
```
|
||||
|
||||
### lcd.setColor(color [,bcolor])
|
||||
设置默认的绘画颜色和背景色,bcolor一般用于设置文字显示的背景色。
|
||||
|
||||
|
||||
### lcd.print(text, [x, y, color])
|
||||
|
||||
显示字符串 *text* 在 *(x, y)* 指定的位置,参数 *color* 为颜色参数。
|
||||
|
||||
(注:在中括号如[x, y, color]内的表示为可选参数)
|
||||
|
||||
* **x**: 指定水平方向的位置显示, 有以下特殊参数:
|
||||
* LASTX(默认), 直接上一个光标的文字接着显示
|
||||
* CENTER, 居中显示文本
|
||||
* RIGHT, 右对齐文本
|
||||
|
||||
* **y**: 指定垂直方向的位置显示, 有以下特殊参数:
|
||||
* LASTX(默认), 直接上一个光标的文字接着显示
|
||||
* CENTER, 居中显示文本
|
||||
* BOTTOM, 文字靠底部显示
|
||||
|
||||
* **color**:如果该参数未设置,默认为 *lcd.setColor* 设置的颜色。
|
||||
|
||||
|
||||
|
||||
### lcd.println(text, [x, y, color])
|
||||
|
||||
lcd.println函数功能与 *lcd.print* 函数功能基本一样,只是会在最后自动换行。
|
||||
|
||||
```python
|
||||
lcd.print('hello world\n')
|
||||
lcd.println('hello world') #显示效果一致
|
||||
```
|
||||
|
||||
|
||||
### lcd.font(font)
|
||||
|
||||
设置字体.
|
||||
|
||||
可以使用内置的字体已定义好的参数:
|
||||
|
||||
**FONT_Default, FONT_DefaultSmall, FONT_DejaVu18, FONT_Dejavu24, FONT_Ubuntu, FONT_Comic, FONT_Minya, FONT_Tooney, FONT_Small, FONT_7seg**
|
||||
|
||||
```python
|
||||
lcd.font(lcd.FONT_Dejavu24) #设置为FONT_Dejavu24字体
|
||||
```
|
||||
|
||||
### lcd.textWidth(text)
|
||||
|
||||
返回字符串 *text* 字体显示占用的宽度。
|
||||
|
||||
|
||||
### lcd.fontSize()
|
||||
|
||||
返回当前字体的 *width* 和 *heigh*。
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
from m5stack import lcd
|
||||
|
||||
#在屏幕上hello world
|
||||
lcd.print('hello world')
|
||||
|
||||
#在屏幕x=10,y=100的地方显示hello world
|
||||
lcd.print('hello world', 10, 100)
|
||||
|
||||
#显示的文字颜色为绿色的hello world
|
||||
lcd.print('hello wrold', color=0xFF0000)
|
||||
|
||||
#在屏幕x=10,y=100的地方显示红色的hello world字体
|
||||
lcd.print('hello world', 10, 200, 0xFF0000)
|
||||
|
||||
#设置字体为FONT_Dejavu24
|
||||
lcd.font(lcd.FONT_Dejavu24)
|
||||
lcd.println('hello world')
|
||||
```
|
||||
|
||||
|
||||
### lcd.pixel(x, y [,color])
|
||||
|
||||
画一个像素点在指定位置 (x,y). 如果 *color* 参数未设置, 则默认使用 *lcd.setColor* 设置的前景色.
|
||||
|
||||
### lcd.line(x, y, x1, y1 [,color])
|
||||
|
||||
画一条直线从坐标(x,y) 到 (x1,y1). 画一个像素点在指定位置 (x,y). 如果 *color* 参数未设置, 则默认使用 *lcd.setColor* 设置的前景色.
|
||||
|
||||
|
||||
### lcd.rect(x, y, width, height, [color, fillcolor])
|
||||
|
||||
画一个矩形,(x,y)为矩形左上角的起始坐标,参数 *width* 和 *height* 为设置矩形的宽度和高度。
|
||||
|
||||
如果 *color* 和 参数未设置, 则默认使用 *lcd.setColor* 设置的前景色.
|
||||
|
||||
可选参数 *fillcolor* 为矩形的填充色。
|
||||
|
||||
```python
|
||||
lcd.rect(10, 100, 100, 200, 0xFF0000) #不填充颜色
|
||||
lcd.rect(10, 100, 100, 200, 0xFF0000, 0x00FF00) #填充矩形内部为绿色
|
||||
```
|
||||
|
||||
### lcd.triangle(x, y, x1, y1, x2, y2 [,color, fillcolor])
|
||||
|
||||
画一个三角形根据指定的三个点 (x,y), (x1,y1) and (x2,y2).
|
||||
|
||||
|
||||
### lcd.circle(x, y, r [,color, fillcolor])
|
||||
|
||||
画一个圆, 参数(x,y)为圆的原点,*r* 为半径.
|
||||
|
||||
|
||||
### lcd.ellipse(x, y, rx, ry [opt, color, fillcolor])
|
||||
|
||||
画一个椭圆 (x,y)和 (rx, ry) 为椭圆的两个焦点.
|
||||
|
||||
**opt* 参数用于显示象限, 默认是 15, 显示整个椭圆.
|
||||
|
||||
Multiple segments can drawn, combine (logical or) the values.
|
||||
* 1 - upper left segment
|
||||
* 2 - upper right segment
|
||||
* 4 - lower left segment
|
||||
* 8 - lower right segment
|
||||
|
||||
If *fillcolor* is given, filled elipse will be drawn.
|
||||
|
||||
|
||||
### lcd.arc(x, y, r, thick, start, end [color, fillcolor])
|
||||
|
||||
画一个圆弧中心点 (x,y), *r* 为半径,*thick* 为边的厚度,起始角度 *start* 和 *end* 角度(0~360度)。
|
||||
|
||||
|
||||
### lcd.poly(x, y, r, sides, thick, [color, fillcolor, rotate])
|
||||
|
||||
画一个多边形中心点 (x,y), *r* 为半径, 参数 *sides* 为多边形的边数,*thick* 为边的厚度。
|
||||
|
||||
如果设置了 *rotate* 参数, 可以旋转多边形的角度 (0~359)
|
||||
|
||||
|
||||
### lcd.roundrect(x, y, width, height, r [color, fillcolor])
|
||||
|
||||
圆角矩形参数 *r* 为圆角的半径.
|
||||
|
||||
|
||||
### lcd.clear([color])
|
||||
|
||||
等价于lcd.fill([color])
|
||||
|
||||
Clear the screen with default background color or specific color if given.
|
||||
|
||||
清除屏幕显示的内容,填充指定的颜色,默认是 *lcd.setColor* 设置的背景色。
|
||||
|
||||
|
||||
### lcd.image(x, y, file [,scale, type])
|
||||
|
||||
显示图片*file*,(x,y)为起始位置
|
||||
* 支持 **JPG** and **BMP** 图片格式.
|
||||
* Constants **lcd.CENTER**, **lcd.BOTTOM**, **lcd.RIGHT** can be used for x&y
|
||||
* **x** and **y** values can be negative
|
||||
|
||||
**scale**: 图片缩放比例
|
||||
|
||||
**type**: 图片的类型 *lcd.JPG* 或 *lcd.BMP*
|
||||
|
||||
## **Button**
|
||||
|
||||
---
|
||||
```python
|
||||
import m5stack as m5
|
||||
|
||||
def press_cb(pin):
|
||||
m5.lcd.println('button_press A')
|
||||
print('button_press A')
|
||||
|
||||
m5.BtnA.set_callback(press_cb)
|
||||
```
|
||||
|
||||
或者:
|
||||
|
||||
```python
|
||||
import m5stack as m5
|
||||
|
||||
while True:
|
||||
if m5.BtnA.press():
|
||||
m5.lcd.println('button_press A')
|
||||
time.sleep_ms(10)
|
||||
|
||||
```
|
||||
|
||||
|
||||
## **SD Card**
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
import uos
|
||||
|
||||
uos.mountsd()
|
||||
uos.listdir('/sd')
|
||||
```
|
||||
|
||||
|
||||
## **Beep**
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
import m5stack as m5
|
||||
|
||||
m5.beep.tone(freq=1800)
|
||||
m5.beep.tone(freq=1800, timeout=200)
|
||||
```
|
||||
|
||||
## **GPIO**
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
import machine
|
||||
|
||||
pinout = machine.Pin(0, machine.Pin.OUT)
|
||||
pinout.value(1)
|
||||
|
||||
pinin = machine.Pin(2, machine.Pin.IN)
|
||||
val = pinin.value()
|
||||
```
|
||||
|
||||
## **PWM**
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
import machine
|
||||
|
||||
pwm = machine.PWM(machine.Pin(3))
|
||||
pwm.freq(5000)
|
||||
pwm.duty(666)
|
||||
```
|
||||
|
||||
|
||||
## **ADC**
|
||||
|
||||
---
|
||||
```python
|
||||
import machine
|
||||
|
||||
adc = machine.ADC(35)
|
||||
adc.read()
|
||||
```
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,85 @@
|
||||
'''
|
||||
Arduino version:
|
||||
https://github.com/dankelley2/M5Stack_BTCTicker
|
||||
|
||||
Response (JSON)
|
||||
last Last BTC price.
|
||||
high Last 24 hours price high.
|
||||
low Last 24 hours price low.
|
||||
vwap Last 24 hours volume weighted average price.
|
||||
volume Last 24 hours volume.
|
||||
bid Highest buy order.
|
||||
ask Lowest sell order.
|
||||
timestamp Unix timestamp date and time.
|
||||
open First price of the day.
|
||||
'''
|
||||
|
||||
from m5stack import *
|
||||
from utils import *
|
||||
import urequests
|
||||
import ujson
|
||||
import utime as time
|
||||
import curl
|
||||
import _thread
|
||||
|
||||
# # Used curl
|
||||
# def get_btc_price():
|
||||
# try:
|
||||
# #r = urequests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
|
||||
# r = curl.get("https://www.bitstamp.net/api/ticker/")
|
||||
# return ujson.loads(r[2])
|
||||
# except:
|
||||
# return False
|
||||
|
||||
|
||||
def main():
|
||||
lcd.clear()
|
||||
lcd.setBrightness(500)
|
||||
lcd.setTextColor(lcd.WHITE, lcd.BLACK)
|
||||
lcd.font('SFArch_48.fon')
|
||||
lcd.print('BTC Price', lcd.CENTER, 25, lcd.ORANGE)
|
||||
prev_price = ''
|
||||
while True:
|
||||
try:
|
||||
# btc_data = get_btc_price()
|
||||
r = urequests.get("https://www.bitstamp.net/api/ticker/")
|
||||
btc_data = ujson.loads(r.text)
|
||||
print(btc_data)
|
||||
if btc_data:
|
||||
# Max price
|
||||
high = btc_data['high'][:-1]
|
||||
lcd.font(lcd.FONT_DejaVu18)
|
||||
lcd.print('Max:', 20, 192, lcd.GREEN)
|
||||
lcd.print(high, 5, 215, lcd.GREEN)
|
||||
|
||||
# Min price
|
||||
low = btc_data['low'][:-1]
|
||||
lcd.font(lcd.FONT_DejaVu18)
|
||||
lcd.print('Min:', 255, 192, lcd.RED)
|
||||
lcd.print(low+' ', lcd.RIGHT, 215, lcd.RED)
|
||||
|
||||
# Last Price
|
||||
price = btc_data['last'][:-1]
|
||||
if not price == prev_price:
|
||||
lcd.rect(0, 100, 320, 48, lcd.BLACK, lcd.BLACK)
|
||||
lcd.font('SFArch_48.fon')
|
||||
lcd.print('$ '+price, lcd.CENTER, 100, color=lcd.WHITE)
|
||||
|
||||
# Symbol
|
||||
_offset = 180
|
||||
if price > prev_price:
|
||||
lcd.rect(140, _offset, 41, 26, lcd.BLACK, lcd.BLACK)
|
||||
lcd.triangle(160,_offset, 140,_offset+25, 180,_offset+25, lcd.GREEN, lcd.GREEN)
|
||||
elif price < prev_price:
|
||||
lcd.rect(140, _offset, 41, 26, lcd.BLACK, lcd.BLACK)
|
||||
lcd.triangle(160,_offset+25, 140,_offset, 180,_offset, lcd.RED, lcd.RED)
|
||||
prev_price = price
|
||||
|
||||
gc.collect()
|
||||
time.sleep(1)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
main()
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
from m5stack import *
|
||||
import time, _thread
|
||||
import time, _thread, machine
|
||||
|
||||
def clock():
|
||||
rtc = machine.RTC()
|
||||
print("Synchronize time from NTP server ...")
|
||||
lcd.println("Synchronize time from NTP server ...")
|
||||
rtc.ntp_sync(server="cn.ntp.org.cn")
|
||||
|
||||
lcd.clear()
|
||||
lcd.font(lcd.FONT_7seg, fixedwidth=True, dist=16, width=2)
|
||||
lcd.setBrightness(200)
|
||||
lcd.font(lcd.FONT_7seg, fixedwidth=True, dist=16, width=2)
|
||||
|
||||
while True:
|
||||
d = time.strftime("%Y-%m-%d", time.localtime())
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -6,7 +6,7 @@ class DHTBaseI2C:
|
||||
def __init__(self, i2c=None, addr=0x5c):
|
||||
if i2c == None:
|
||||
from machine import I2C
|
||||
self.i2c = I2C()
|
||||
self.i2c = I2C(sda=21, scl=22)
|
||||
else:
|
||||
self.i2c = i2c
|
||||
self.addr = addr
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ M5Stack MicroPython FACES keyboard I2C driver
|
||||
class Faces:
|
||||
def __init__(self):
|
||||
from machine import I2C
|
||||
self.i2c = I2C()
|
||||
self.i2c = I2C(sda=21, scl=22)
|
||||
self.addr = 0x08
|
||||
self.cb = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user