本文是上篇的延续,可以测量从LED亮到按下按钮的具体时长,并显示出来。但在功能增加的同时,占用的晶体管资源增加了多少呢?得到有效利用的又有多少呢?

目录

一、Arduino是什么?

二、部件

1.Arduino uno

简介:

引脚图:

Hello World:

2.SH1106

驱动程序:

二、主程序

总结


一、Arduino是什么?

What is Arduino?

Arduino designs, manufactures, and supports electronic devices and software, allowing people around the world to easily access advanced technologies that interact with the physical world. Our products are straightforward, simple, and powerful, ready to satisfy users’ needs from students to makers and all the way to professional developers.

Find out morehttps://www.arduino.cc/en/Guide/Introduction

Our Mission & Vision

Arduino’s mission is to enable anyone to enhance their lives through accessible electronics and digital technologies. There was once a barrier between the electronics, design, and programming world and the rest of the world. Arduino has broken down that barrier.

Over the years, our products have been the brains behind thousands of projects, from everyday objects to complex scientific instruments. A worldwide community, comprising students, hobbyists, artists, programmers, and professionals, has gathered around this open-source platform, their contributions adding up to an incredible amount of accessible knowledge.

Our vision is to make Arduino available to everyone, whether you are a student, maker or professional, which is why we now have three segments to our business. These segments work together as an ecosystem with a shared mindset: we started with Maker, and that has evolved into Education and PRO solutions.

二、部件

1.Arduino uno

简介:

Overview

Arduino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.. You can tinker with your Uno without worrying too much about doing something wrong, worst case scenario you can replace the chip for a few dollars and start over again.

"Uno" means one in Italian and was chosen to mark the release of Arduino Software (IDE) 1.0. The Uno board and version 1.0 of Arduino Software (IDE) were the reference versions of Arduino, now evolved to newer releases. The Uno board is the first in a series of USB Arduino boards, and the reference model for the Arduino platform; for an extensive list of current, past or outdated boards see the Arduino index of boards.

Tech specs

Microcontroller ATmega328P
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
PWM Digital I/O Pins 6
Analog Input Pins 6
DC Current per I/O Pin 20 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega328P) of which 0.5 KB used by bootloader
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
Clock Speed 16 MHz
LED_BUILTIN 13
Length 68.6 mm
Width 53.4 mm
Weight 25 g

引脚图:

Hello World:

// the setup function runs once when you press reset or power the board
void setup() {// initialize digital pin LED_BUILTIN as an output.pinMode(LED_BUILTIN, OUTPUT);
}// the loop function runs over and over again forever
void loop() {digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)delay(1000);                       // wait for a seconddigitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOWdelay(1000);                       // wait for a second
}

2.SH1106

这里原本是要用mega2560的,但新手入门,不知到屏怎么连,网上也没有现成的解决方案。最后还是买了块uno,解决了问题。所以入门省事还是建议uno。

驱动程序:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>#define OLED_MOSI     10
#define OLED_CLK      8
#define OLED_DC       7
#define OLED_CS       5
#define OLED_RST      9// Create the OLED display
Adafruit_SH1106G display = Adafruit_SH1106G(128, 64,OLED_MOSI, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,B00000001, B11000000,B00000001, B11000000,B00000011, B11100000,B11110011, B11100000,B11111110, B11111000,B01111110, B11111111,B00110011, B10011111,B00011111, B11111100,B00001101, B01110000,B00011011, B10100000,B00111111, B11100000,B00111111, B11110000,B01111100, B11110000,B01110000, B01110000,B00000000, B00110000
};void setup()   {Serial.begin(9600);//display.setContrast (0); // dim display// Start OLEDdisplay.begin(0, true); // we dont use the i2c address but we will reset!// Show image buffer on the display hardware.// Since the buffer is intialized with an Adafruit splashscreen// internally, this will display the splashscreen.display.display();delay(2000);// Clear the buffer.display.clearDisplay();// draw a single pixeldisplay.drawPixel(10, 10, SH110X_WHITE);// Show the display buffer on the hardware.// NOTE: You _must_ call display after making any drawing commands// to make them visible on the display hardware!display.display();delay(2000);display.clearDisplay();// draw many linestestdrawline();display.display();delay(2000);display.clearDisplay();// draw rectanglestestdrawrect();display.display();delay(2000);display.clearDisplay();// draw multiple rectanglestestfillrect();display.display();delay(2000);display.clearDisplay();// draw mulitple circlestestdrawcircle();display.display();delay(2000);display.clearDisplay();// draw a SH110X_WHITE circle, 10 pixel radiusdisplay.fillCircle(display.width() / 2, display.height() / 2, 10, SH110X_WHITE);display.display();delay(2000);display.clearDisplay();testdrawroundrect();delay(2000);display.clearDisplay();testfillroundrect();delay(2000);display.clearDisplay();testdrawtriangle();delay(2000);display.clearDisplay();testfilltriangle();delay(2000);display.clearDisplay();// draw the first ~12 characters in the fonttestdrawchar();display.display();delay(2000);display.clearDisplay();// text display testsdisplay.setTextSize(1);display.setTextColor(SH110X_WHITE);display.setCursor(0, 0);display.println("Failure is always an option");display.setTextColor(SH110X_BLACK, SH110X_WHITE); // 'inverted' textdisplay.println(3.141592);display.setTextSize(2);display.setTextColor(SH110X_WHITE);display.print("0x"); display.println(0xDEADBEEF, HEX);display.display();delay(2000);display.clearDisplay();// miniature bitmap displaydisplay.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);display.display();delay(1);// invert the displaydisplay.invertDisplay(true);delay(1000);display.invertDisplay(false);delay(1000);display.clearDisplay();// draw a bitmap icon and 'animate' movementtestdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
}void loop() {}void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {uint8_t icons[NUMFLAKES][3];// initializefor (uint8_t f = 0; f < NUMFLAKES; f++) {icons[f][XPOS] = random(display.width());icons[f][YPOS] = 0;icons[f][DELTAY] = random(5) + 1;Serial.print("x: ");Serial.print(icons[f][XPOS], DEC);Serial.print(" y: ");Serial.print(icons[f][YPOS], DEC);Serial.print(" dy: ");Serial.println(icons[f][DELTAY], DEC);}while (1) {// draw each iconfor (uint8_t f = 0; f < NUMFLAKES; f++) {display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SH110X_WHITE);}display.display();delay(200);// then erase it + move itfor (uint8_t f = 0; f < NUMFLAKES; f++) {display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SH110X_BLACK);// move iticons[f][YPOS] += icons[f][DELTAY];// if its gone, reinitif (icons[f][YPOS] > display.height()) {icons[f][XPOS] = random(display.width());icons[f][YPOS] = 0;icons[f][DELTAY] = random(5) + 1;}}}
}void testdrawchar(void) {display.setTextSize(1);display.setTextColor(SH110X_WHITE);display.setCursor(0, 0);for (uint8_t i = 0; i < 168; i++) {if (i == '\n') continue;display.write(i);if ((i > 0) && (i % 21 == 0))display.println();}display.display();delay(1);
}void testdrawcircle(void) {for (int16_t i = 0; i < display.height(); i += 2) {display.drawCircle(display.width() / 2, display.height() / 2, i, SH110X_WHITE);display.display();delay(1);}
}void testfillrect(void) {uint8_t color = 1;for (int16_t i = 0; i < display.height() / 2; i += 3) {// alternate colorsdisplay.fillRect(i, i, display.width() - i * 2, display.height() - i * 2, color % 2);display.display();delay(1);color++;}
}void testdrawtriangle(void) {for (int16_t i = 0; i < min(display.width(), display.height()) / 2; i += 5) {display.drawTriangle(display.width() / 2, display.height() / 2 - i,display.width() / 2 - i, display.height() / 2 + i,display.width() / 2 + i, display.height() / 2 + i, SH110X_WHITE);display.display();delay(1);}
}void testfilltriangle(void) {uint8_t color = SH110X_WHITE;for (int16_t i = min(display.width(), display.height()) / 2; i > 0; i -= 5) {display.fillTriangle(display.width() / 2, display.height() / 2 - i,display.width() / 2 - i, display.height() / 2 + i,display.width() / 2 + i, display.height() / 2 + i, SH110X_WHITE);if (color == SH110X_WHITE) color = SH110X_BLACK;else color = SH110X_WHITE;display.display();delay(1);}
}void testdrawroundrect(void) {for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, SH110X_WHITE);display.display();delay(1);}
}void testfillroundrect(void) {uint8_t color = SH110X_WHITE;for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color);if (color == SH110X_WHITE) color = SH110X_BLACK;else color = SH110X_WHITE;display.display();delay(1);}
}void testdrawrect(void) {for (int16_t i = 0; i < display.height() / 2; i += 2) {display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, SH110X_WHITE);display.display();delay(1);}
}void testdrawline() {for (int16_t i = 0; i < display.width(); i += 4) {display.drawLine(0, 0, i, display.height() - 1, SH110X_WHITE);display.display();delay(1);}for (int16_t i = 0; i < display.height(); i += 4) {display.drawLine(0, 0, display.width() - 1, i, SH110X_WHITE);display.display();delay(1);}delay(250);display.clearDisplay();for (int16_t i = 0; i < display.width(); i += 4) {display.drawLine(0, display.height() - 1, i, 0, SH110X_WHITE);display.display();delay(1);}for (int16_t i = display.height() - 1; i >= 0; i -= 4) {display.drawLine(0, display.height() - 1, display.width() - 1, i, SH110X_WHITE);display.display();delay(1);}delay(250);display.clearDisplay();for (int16_t i = display.width() - 1; i >= 0; i -= 4) {display.drawLine(display.width() - 1, display.height() - 1, i, 0, SH110X_WHITE);display.display();delay(1);}for (int16_t i = display.height() - 1; i >= 0; i -= 4) {display.drawLine(display.width() - 1, display.height() - 1, 0, i, SH110X_WHITE);display.display();delay(1);}delay(250);display.clearDisplay();for (int16_t i = 0; i < display.height(); i += 4) {display.drawLine(display.width() - 1, 0, 0, i, SH110X_WHITE);display.display();delay(1);}for (int16_t i = 0; i < display.width(); i += 4) {display.drawLine(display.width() - 1, 0, i, display.height() - 1, SH110X_WHITE);display.display();delay(1);}delay(250);
}

二、主程序

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>#define OLED_MOSI     10 sda
#define OLED_CLK      8 sck
#define OLED_DC       7
#define OLED_CS       5
#define OLED_RST      9// Create the OLED display
Adafruit_SH1106G display = Adafruit_SH1106G(128, 64,OLED_MOSI, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16const int buttonpin = 2;
const int ledpin = 13;
int buttonpintwo;
int startsignal;
unsigned long timebox;
unsigned long rtime1;
unsigned long rtime2;static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,B00000001, B11000000,B00000001, B11000000,B00000011, B11100000,B11110011, B11100000,B11111110, B11111000,B01111110, B11111111,B00110011, B10011111,B00011111, B11111100,B00001101, B01110000,B00011011, B10100000,B00111111, B11100000,B00111111, B11110000,B01111100, B11110000,B01110000, B01110000,B00000000, B00110000
};void setup()   {Serial.begin(9600);//display.setContrast (0); // dim display// Start OLEDdisplay.begin(0, true); // we dont use the i2c address but we will reset!// Show image buffer on the display hardware.// Since the buffer is intialized with an Adafruit splashscreen// internally, this will display the splashscreen.//display.display();//delay(2000);// Clear the buffer.display.clearDisplay();display.setCursor(8, 24);display.setTextSize(1);display.setTextColor(SH110X_WHITE);display.println("HAND SPEED TEST");display.setCursor(8, 36);display.println("Ver:  0.1");display.setCursor(8, 48);display.println("Date: 20220820");display.display();delay(2000);display.clearDisplay(); pinMode (buttonpin,INPUT);pinMode (ledpin,OUTPUT);digitalWrite (ledpin,HIGH);delay (500);digitalWrite (ledpin,LOW);delay (500); startsignal=1;
}void loop() {if(startsignal==1) {display.clearDisplay();display.setCursor(8, 8);display.setTextSize(2);display.setTextColor(SH110X_WHITE);display.println(" Look at ");display.println("  ");display.println("   LED!!!");display.display();rtime1=millis();}digitalWrite (ledpin,HIGH);startsignal=0;buttonpintwo=digitalRead(buttonpin);if(buttonpintwo==HIGH) { digitalWrite(ledpin,LOW);rtime2=millis();timebox=rtime2-rtime1;//Serial.print(timebox);//Serial.print("ms");//oleddisplay.clearDisplay();display.setCursor(0, 8);display.setTextSize(1);display.setTextColor(SH110X_WHITE);display.println("Your hand speed is ");display.setTextSize(2);display.setCursor(24, 24);if(timebox<999){display.print(timebox);display.println("ms"); }else{ display.println(">1s"); }display.display();delay(5000);display.clearDisplay();startsignal=1;}
}

总结

arduino uno板(ATmega328P)的性能相比于555有了巨大的飞跃。通过arduino uno板(ATmega328P)实现的时间间隔感测试器的功能相比于通过555的实现多了很多。也基本了解了屏的驱动方法。

时间间隔感测试器(下):Arduino uno相关推荐

  1. 时间间隔感测试器2.0

    最近在学习SOLIDWORKS 2021,想找一个之前已经做好的东西升级一下外观,做的好看一点.之前做的时间间隔感测试器正好符合这个条件:模块不多,稍微改进即可缩小尺寸,变成可以放在手里的掌机了! 1 ...

  2. arduino uno电压_Arduino UNO中文数据手册

    Arduino UNO数据手册 uno.jpg (65.33 KB, 下载次数: 267) 2018-9-23 15:21 上传 概述 Arduino UNO是基于ATmega328P的Arduino ...

  3. Arduino之Arduino UNO数据手册

    概述 Arduino UNO是基于ATmega328P的Arduino开发板.它有14个数字输入/输出引脚(其中6个可用于PWM输出).6个模拟输入引脚,一个16 MHz的晶体振荡器,一个USB接口, ...

  4. arduino超声波测距接线图详细_使用Arduino UNO开发板和超声波传感器测量距离

    超声波传感器不仅提供距离测量实用程序,而且没有任何物理接触,但需要我们在无噪音和光线的情况下进行测量,与基于激光的距离测量仪器不同.此外,即使在基于激光的仪器经常降低其效率的日光下,这些仪器也便宜且更 ...

  5. Arduino UNO数据手册

    概述 Arduino UNO是基于ATmega328P的Arduino开发板.它有14个数字输入/输出引脚(其中6个可用于PWM输出).6个模拟输入引脚,一个16 MHz的晶体振荡器,一个USB接口, ...

  6. Arduino UNO控制带AB相磁通量式编码器电动推杆(测试阻尼)实录(L289N电机驱动)

    前段时间为了测试实验器材的阻尼,需要去开发一套装置来测试.提出用Arduino单片机来控制电动推杆(Linear Actuator)来制造相应速度的运动,搭配上测力计,从而根据来测得阻尼,在这里简单记 ...

  7. Arduino UNO 摇杆测试实例

    Arduino UNO 摇杆测试实例 摇杆测试数据 X轴(A0)方向的值范围:0-346 Y(A1)轴方向的值范围:0-351 SW的值是按压触发值,0或者1,接的是数字引脚 当然如果需要将取值范围扩 ...

  8. 基于atmega8的arduino最小系统制作(arduino uno作为下载器)

    我们在最小系统的制作过程中,常常会遇到下载器驱动安装不成功的问题,绝大多数原因是因为下载器驱动不兼容win10系统.而当用arduino uno作为下载器为最小系统烧录程序的话,不但解决了win10下 ...

  9. Arduino UNO测试BME680环境传感器

    原文链接:https://www.yourcee.com/newsinfo/2929148.html BME680简介 BME680是一个四合一数字环境检测传感器,可以测量所处周围环境的温度.湿度.气 ...

最新文章

  1. Python 修改终端输入字体颜色值
  2. 深度学习时间序列预测:LSTM算法构建时间序列单变量模型预测大气压( air pressure)+代码实战
  3. Windows下Redis中RedisQFork位置调整
  4. on 和where条件的放置详解
  5. wordpress archive.php,哪个网址将导致wordpress使用archive.php?
  6. CH - 0701 国王游戏(贪心+高精度运算)
  7. 再来说说我喜欢的 Dotnet 5.0 C# 9
  8. Java 8中的HashMap性能改进
  9. 字符搜索正则表达式语法详解
  10. IIS虚拟目录实现与文件服务器网络驱动器映射共享
  11. CSS3边框图片、边框阴影、文本阴影
  12. 批量关停azure vm_如何从Azure VM数据库运行本地SQL报表
  13. 百度地图java批量获得经纬度_从百度地图API接口批量获取地点的经纬度
  14. Sql Server实现自动增长
  15. springmvc全局异常处理ControllerAdvice区分返回响应类型是页面还是JSON
  16. python微信聊天机器人_教你用Python创建微信聊天机器人
  17. 圆锥形怎么画_如何画圆锥体的展开图?
  18. AndroidStudio 导出AAB格式上传谷歌提示超过150M 解决方案
  19. OFN鼠标驱动(三) -- I2C驱动的移植(2)
  20. 分布式事务专题-基础概念(1)

热门文章

  1. Android之Wifi使用
  2. 海思SDK学习(10)海思媒体处理软件平台MMP(9)AUDIO音频
  3. 编译 pg_repack
  4. 微信windows版_微信多开教程:Win、Mac、iOS、Android
  5. 关于购物网站的设计概念
  6. 【python爬虫】学习笔记1-爬取某网站妹子图片
  7. HTTP/HTPPS协议
  8. 把我本科2年爬过的坑,送给高考完想要选计算机专业的你,成为人们眼中的大神吧
  9. 「DLP-KDD 2021征文」及上届论文全集,包含深度学习推荐/广告系统、多目标、模型服务等
  10. 架构文摘:LSV负载均衡技术笔记