我刚刚开始学习微控制器,我无法理解如何在不使用定时器的情况下在代码中引入延迟.我的主板有16MHZ的时钟.假设我想在检查是否按下按钮之前引入5ms延迟.我如何确定需要执行多少指令才能获得5 ms的延迟以及如何对其进行编程?这样做有标准化的方法吗?它看起来像一个非常标准的东西,但我无法理解它是如何完成的.
我在Atmega 328 Arduino uno上使用汇编语言进行编程.
我只是想做这样的事情:
int moduleDecision(int ModuleSelect)
{
if (ModuleSelect == Nmodules)
{
ModuleSelect == 0x00;
return (break);
}
else
{
ModuleSelect = ModuleSelect + 0x01;
return ModuleSelect;
}
}
Run Code Online (Sandbox Code Playgroud)
我在更大的内部调用此函数switch,所以我希望能够退出交换机if ModuleSelect == 0x00.
为什么它不起作用?
此示例草图显示了如何使用setCursor()方法重新定位光标。要移动光标,只需调用具有行和列位置的setCursor()即可。例如,对于2x16显示器:
lcd.setCursor(0, 0); // top left
lcd.setCursor(15, 0); // top right
lcd.setCursor(0, 1); // bottom left
lcd.setCursor(15, 1); // bottom right
Run Code Online (Sandbox Code Playgroud)
我无法理解以上代码。任何人都可以提供相同的说明吗?
我买的液晶显示器不工作,我不知道为什么!当我上传代码时,显示屏仅亮起,但没有显示任何内容!有什么帮助吗?
我的 LCD 型号:1602A 带 I2C (16x2)就像这里的这个
地址:0x27(使用I2C扫描码检查)
代码:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
lcd.begin(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("hello everyone");
lcd.setCursor(1,1);
lcd.print("I am Giga Blitz");
}
void loop() {
}
Run Code Online (Sandbox Code Playgroud)
示意图: 点击此处查看图片
问题出在数组上。声明数组的那行没有问题,是它后面的那一行。似乎我无法像在 C 中那样编码。为了清晰起见,我如何在需要这种格式时修复它。我不想写很长的一行,因为这个数组中有 15 个变量。
这是代码
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)
///// void setup /////
void setup() {
Serial.begin(9600);
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
delay(10);
}
///// Coordonnees /////
int angles[5][3]; //angles de chaque moteur pour chaque cube
angles[0][0]=60;
angles[0][1]=120;
angles[0][2]=100;
Run Code Online (Sandbox Code Playgroud)
基本上它angles[0][0]=;是导致问题的和与它相似的线。
我想制作一个简单的程序,放在我的 Arduino/Genuino (SunFounder) Uno 板上,当插入时,它会调用该Keyboard.print()函数。当我编译程序来执行此操作时,它说我没有包含在内,Keyboard.h即使我实际上处于程序的开头。
#include <Keyboard.h>
void setup() {
Keyboard.begin();
Keyboard.print("Hello, world!");
Keyboard.end();
}
void loop() {
}
Run Code Online (Sandbox Code Playgroud)
当我编译代码时,出现以下错误:
KeyboardMessage:4:3: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
我在 Arduino 草图编辑器文件中检查了我的库文件,并且Keyboard.h它在那里。
任何帮助表示赞赏。
我使用此代码检查了Arduino引脚8的状态。查看该引脚是高电平还是低电平,但是我的输出从高电平连续变为低电平。
运行此代码时,我没有将任何东西连接到引脚8。
const int Pin = 8;
int Reading=0;
void setup() {
Serial.begin(9600);
delay(2000);
pinMode(Pin, INPUT);
}
void loop() {
Reading = digitalRead(Pin);
if(Reading == HIGH)
{
Serial.println("HIGH");
delay(2000);
}
if(Reading == LOW)
{
Serial.println("LOW");
delay(2000);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我的输出是这样的:输出:
HIGH
HIGH
LOW
LOW
HIGH
HIGH
LOW
LOW
HIGH
HIGH
LOW
LOW
HIGH
HIGH
LOW
LOW
Run Code Online (Sandbox Code Playgroud)
不知道该怎么办??
我知道当我们购买 NodeMCU 时,我们会在其中安装 NodeMCU 固件。但是我们为什么能够在这个开发工具包中使用 Arduino IDE(用于 C++ 编程)?
我们如何使用 C++ IDE 来处理基于 Lua 的固件?我这里的概念有什么问题?
我试图使用if语句在Arduino Uno板上使用C控制电机.但是,当我设置为当传感器的PIN等于0时,电机将运行,它根本不起作用.我也尝试将PIN设置为不等于0和1,两者都正常工作.你们可以给它一张支票吗?非常感谢你.
int MotorL=11;
int DirectionR=12;
int MotorR=10;
int DirectionL=13;
int SensorM=0;
#include <avr/io.h>
#include <util/delay.h>
void setup() {
pinMode(DirectionL,OUTPUT);
pinMode(DirectionR,OUTPUT);
pinMode(SensorM,INPUT);
digitalWrite(DirectionL,HIGH);
digitalWrite(DirectionR,HIGH);
analogWrite(MotorL,0);
analogWrite(MotorR,0);
}
void loop() {
if(PIND &_BV(PD6)==0){ //General movement: forward
analogWrite(MotorL,84);
analogWrite(MotorR,97);
}else{
analogWrite(MotorL,0);
analogWrite(MotorR,0);
}
}
Run Code Online (Sandbox Code Playgroud) 我是编码的初学者,尤其是Arduino.我一直在做很多项目,但我遇到了一个问题.我似乎无法弄清楚如何进行有限循环.我正在看一个类似于while循环的东西,它在四次后停止.这里是实施的地方,让您更好地了解我在寻找什么.
#include <Servo.h>
int thumbPin = 2;
int ndxPin = 3;
int midPin = 4;
int rngPin = 5;
int pnkyPin = 6;
Servo thumb;
Servo index;
Servo middle;
Servo ring;
Servo pinky;
void setup() {
Serial.begin(9600);
thumb.attach(thumbPin);
index.attach(ndxPin);
middle.attach(midPin);
ring.attach(rngPin);
pinky.attach(pnkyPin);
}
void loop() {
/* I want this code in the comment to be ran four times, then continued on to the code after
thumb.write(0);
delay(20);
thumb.write(0);
index.write(0);
middle.write(0);
ring.write(0);
pinky.write(0);
thumb.write(150);
index.write(150);
middle.write(150);
ring.write(150);
pinky.write(150); …Run Code Online (Sandbox Code Playgroud) arduino-uno ×10
arduino ×8
arduino-ide ×4
c++ ×3
c ×2
lcd ×2
arrays ×1
assembly ×1
atmega ×1
delay ×1
electronics ×1
instructions ×1
lua ×1
nodemcu ×1
types ×1