Last active
May 6, 2021 11:32
-
-
Save lgh06/199a78f868d8576f5364369e23e3e21f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Blink | |
Turns an LED on for one second, then off for one second, repeatedly. | |
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO | |
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to | |
the correct LED pin independent of which board is used. | |
If you want to know what pin the on-board LED is connected to on your Arduino | |
model, check the Technical Specs of your board at: | |
https://www.arduino.cc/en/Main/Products | |
modified 8 May 2014 | |
by Scott Fitzgerald | |
modified 2 Sep 2016 | |
by Arturo Guadalupi | |
modified 8 Sep 2016 | |
by Colby Newman | |
This example code is in the public domain. | |
http://www.arduino.cc/en/Tutorial/Blink | |
*/ | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
int serialPort = 5; | |
int brightness = 10; | |
boolean plus = true; | |
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display | |
// 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); | |
pinMode(serialPort, OUTPUT); | |
//Serial.begin(9600); | |
lcd.init(); // initialize the lcd | |
// Print a message to the LCD. | |
lcd.backlight(); | |
lcd.print("Hello, world!"); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
if(plus == true) { | |
brightness+=5; | |
}else if (plus == false){ | |
brightness-=5; | |
} | |
//Serial.println(brightness); | |
lcd.print(brightness); | |
lcd.print(" "); | |
if(brightness == 5) { | |
plus = true; | |
analogWrite(serialPort, 0); | |
delay(2500); | |
lcd.backlight(); | |
}else if (brightness == 255) { | |
plus = false; | |
delay(2500); | |
lcd.noBacklight(); | |
} | |
analogWrite(serialPort, brightness); | |
delay(100); | |
//Serial.println(analogRead(A0)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Blink | |
Turns an LED on for one second, then off for one second, repeatedly. | |
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO | |
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to | |
the correct LED pin independent of which board is used. | |
If you want to know what pin the on-board LED is connected to on your Arduino | |
model, check the Technical Specs of your board at: | |
https://www.arduino.cc/en/Main/Products | |
modified 8 May 2014 | |
by Scott Fitzgerald | |
modified 2 Sep 2016 | |
by Arturo Guadalupi | |
modified 8 Sep 2016 | |
by Colby Newman | |
This example code is in the public domain. | |
http://www.arduino.cc/en/Tutorial/Blink | |
*/ | |
int serialPort = 5; | |
int brightness = 10; | |
boolean plus = true; | |
// 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); | |
pinMode(serialPort, OUTPUT); | |
//Serial.begin(9600); | |
} | |
// the loop function runs over and over again forever | |
void loop() { | |
if(plus == true) { | |
brightness+=5; | |
}else if (plus == false){ | |
brightness-=5; | |
} | |
//Serial.println(brightness); | |
if(brightness == 5) { | |
plus = true; | |
analogWrite(serialPort, 0); | |
delay(2500); | |
}else if (brightness == 255) { | |
plus = false; | |
} | |
analogWrite(serialPort, brightness); | |
delay(40); | |
//Serial.println(analogRead(A0)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
将从机与arduino开发板通过IIC接口连接好。 | |
SDA-->A4 | |
SCK-->A5 | |
上传以下代码至arudino,观察串口返回的结果。 | |
Name: IICaddressFound.ino | |
Created: 2018/10/14 14:42:57 | |
Author: ipenn | |
*/ | |
#include <Wire.h> //(将 IIC 所需的Wire.h头文件包含进来) | |
// the setup function runs once when you press reset or power the boardvoid setup() { | |
Serial.begin(9600);//(开启串口,以接受结果) | |
Wire.begin();//(初始化IIC连接,作为主机无需参数) | |
for (int i = 0; i < 127; i++)//(IIC 地址从0~127(十进制),一共128个遍历一遍就知道结果了) { | |
Wire.beginTransmission(i);//(和地址i连接) | |
int error = Wire.endTransmission();//(结束和地址i的连接,并接受返回值(只可能是0~4其中的一个值)。其中0表示成功) | |
if (error == 0) { | |
//(如果返回值是0(成功)的话就返回地址,以十六进制) | |
Serial.println(); | |
Serial.print("Device is found at : 0x"); | |
Serial.println(i,HEX); | |
} | |
} | |
} | |
// the loop function runs over and over again until power down or reset | |
void loop() { }// loop 里什么都不干 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Serial相关代码 指定波特率 把数据传回电脑