当前位置:网站首页>Arduino- how to light the LED?
Arduino- how to light the LED?
2022-07-24 09:46:00 【Jiang tengxia】
Elementary lighting
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Advanced lighting
1> Light a light , Execute other code again
int ledPin = 13; // LED connected to digital pin 13
int value = LOW; // previous value of the LED
long previousMillis = 0; // will store last time LED was updated Last activation time
long interval = 1000; // interval at which to blink (milliseconds) interval
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, is the difference
// between the current time and last time we blinked the LED bigger than
// the interval at which we want to blink the LED.
if (millis() - previousMillis > interval) {
previousMillis = millis(); // remember the last time we blinked the LED
// if the LED is off turn it on and vice-versa.
if (value == LOW)
value = HIGH;
else
value = LOW;
digitalWrite(ledPin, value);
}
}
2> Button lighting
int ledPin = 13; // choose the pin for the LED
int inPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
}
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) {
// check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
}
边栏推荐
- 配置系统环境变量的时候误删了Path怎么办?
- 缓冲区的概念真的理解么?带你揭开缓冲区的面纱~
- Onpropertychange property
- CAS principle [concurrent programming]
- Common evaluation indexes of medical image segmentation
- js定位大全获取节点的兄弟,父级,子级元素含robot实例
- Foreign lead operation takes one month to collect money, and the sideline still needs it
- Build practical product help documents to improve user satisfaction
- [don't bother to strengthen learning] video notes (II) 1. What is Q-learning?
- [don't bother to strengthen learning] video notes (III) 3. SARS (lambda)
猜你喜欢

RxJS Beginner Guide

配置系统环境变量的时候误删了Path怎么办?

The most complete solution for distributed transactions
![[don't bother to strengthen learning] video notes (II) 2. Write a small example of Q learning](/img/b1/d5c869bc68ba273be2030202f94a55.png)
[don't bother to strengthen learning] video notes (II) 2. Write a small example of Q learning

Li Kou 300 longest increasing subsequence dynamic programming
![[don't bother with intensive learning] video notes (III) 1. What is SARS?](/img/5c/4636db2849ba8514976a5afaf56e38.png)
[don't bother with intensive learning] video notes (III) 1. What is SARS?

【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)

ASI-20220222-Implicit PendingIntent
![Cyclicbarrier and countdownlatch [concurrent programming]](/img/38/3305a0cdb6de40e1370cc93c8e5014.png)
Cyclicbarrier and countdownlatch [concurrent programming]

Spark Learning: compile spark source code in win10
随机推荐
JS bind simulation
Android Version Description security privacy 13
Hucang integrated e-commerce project (I): introduction to the project background and structure
Understanding of magnetic parameters in Hall sensors
Detailed LinkedList
JS 84*148=b6a8 how many decimal places can you make both sides equal
Add SSH key to bitbucket
S2b2b system standardizes the ordering and purchasing process and upgrades the supply chain system of household building materials industry
Spark Learning: compile spark source code in win10
Little dolphin "transformed" into a new intelligent scheduling engine, which can be explained in simple terms in the practical development and application of DDS
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
What's the difference between testing / developing programmers' professionalism and salted fish? They don't want to be excellent coders?
Compilation and linking of programs
DSP development, using CCS software to establish engineering and burning
Scarcity in Web3: how to become a winner in a decentralized world
Vim: extend the semantic analysis function of YCM for the third-party library of C language
Scheme and software analysis of dual computer hot standby system "suggestions collection"
Dark king | analysis of zego low illumination image enhancement technology
PHP caching system - PHP uses Memcache
MySQL Basics (I) -- SQL Basics