#include <Adafruit_ST7735.h>
#include <SPI.h>
// 定义TFT LCD引脚
#define TFT_SCLK 13 // SCL
#define TFT_MOSI 11 // SDA
#define TFT_RST 9 // RES
#define TFT_DC 8 // DC
#define TFT_CS 10 // CS
// 定义按钮引脚
#define BUTTON_PIN 2
// 创建TFT LCD对象
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
// 定义输入引脚
const int inputPin = A0;
bool isRunning = false;
void setup() {
// 设置按钮引脚为输入模式
pinMode(BUTTON_PIN, INPUT_PULLUP);
// 设置SPI时钟频率
SPI.setClockDivider(SPI_CLOCK_DIV16); // 1 MHz
// 初始化TFT LCD
tft.initR(INITR_BLACKTAB);
tft.setRotation(1);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.setCursor(0, 0);
tft.println("Oscilloscope");
}
void loop() {
// 检查按钮状态
if (digitalRead(BUTTON_PIN) == LOW) {
isRunning = !isRunning;
delay(200); // 防止按钮抖动
}
if (isRunning) {
// 读取输入引脚的值
int value = analogRead(inputPin);
// 清空TFT LCD
tft.fillScreen(ST7735_BLACK);
// 绘制波形
for (int x = 0; x < 144; x++) {
int y = map(value, 0, 1023, 0, 159);
tft.drawPixel(x, y, ST7735_WHITE);
value = analogRead(inputPin);
delayMicroseconds(1); // 将采样频率设置为 1 MHz
}
} else {
tft.setCursor(0, 20);
tft.println("Press button to start");
}
}
As your topic does not relate directly to the installation or operation of the IDE it has been moved to the Programming Questions category of the forum
Do you have a question relating to the code that you posted ?
YES it is
Sorry but I don't understand what you are saying
I repeat, do you have a question about the code that you posted ?
yes it's not correct
We are making slow progress because you are not providing good information
- Which Arduino board are you using ?
- Does the code compile ?
- If it compiles what does it do or not do ?
NANO
Yes
It's can't Detect high HZ
What is your definition of high frequency in this case ?
#include <Adafruit_ST7735.h>
#include <SPI.h>
// 创建TFT LCD对象 CS, DC, MOSI, SCLK, RST
Adafruit_ST7735 tft = Adafruit_ST7735 (10, 8, 11, 13, 9);
// 定义输入引脚
const int inputPin = A0;
const byte BUTTON_PIN = 2;
byte butState;
bool isRunning = false;
const int BufSize = 144;
int buf [BufSize];
// -----------------------------------------------------------------------------
void loop ()
{
byte but = digitalRead (BUTTON_PIN);
if (butState != but) { // change
butState = but;
delay (20); // debounce
if (LOW == but)
isRunning = !isRunning;
}
if (! isRunning)
return;
// capture samples -- max ~10000/sec
for (int n = 0; n < BufSize; n++)
buf [n] = analogRead (inputPin);
// display samples
tft.fillScreen (ST7735_BLACK); // 清空TFT LCD
for (int n = 0; n < BufSize; n++) {
int y = map (buf [n], 0, 1023, 0, 159);
tft.drawPixel (n, y, ST7735_WHITE);
}
}
// -----------------------------------------------------------------------------
void setup () {
// 设置按钮引脚为输入模式
pinMode (BUTTON_PIN, INPUT_PULLUP);
butState = digitalRead (BUTTON_PIN);
// 设置SPI时钟频率
SPI.setClockDivider (SPI_CLOCK_DIV16); // 1 MHz
// 初始化TFT LCD
tft.initR (INITR_BLACKTAB);
tft.setRotation (1);
tft.fillScreen (ST7735_BLACK);
tft.setTextColor (ST7735_WHITE);
tft.setTextSize (1);
tft.setCursor (0, 0);
tft.println ("Oscilloscope");
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.