arduino

arduino学习笔记二十一--PWM控制LED 呼吸灯

拜拜、爱过 提交于 2019-12-14 11:28:51
实验用到的元件 , 一个LED, 一个470欧姆电阻 2根杜邦线, 一块实验板。 原理图 LED长脚的为正,短脚为负极。 LED的正极连接 IO口9,LED负极连接电阻,电阻的另外一端接GND. 代码: int brightness = 0; //定义整数型变量brightness与其初始值,此变量用来表示LED的亮度。 int fadeAmount = 5; //定义整数型变量fadeAmount,此变量用来做亮度变化的增减量。 void setup() { pinMode(9, OUTPUT);// 设置9号口为输出端口: } void loop() { analogWrite(9, brightness);//把brightness的值写入9号端口 brightness = brightness + fadeAmount;//改变brightness值,使亮度在下一次循环发生改变 if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; //在亮度最高与最低时进行翻转 } delay(30); //延时30毫秒 } 来源: CSDN 作者: 甜航一直在 链接: https://blog.csdn.net/qq_37631068/article/details/103447698

Arduino compile error while using reference to a struct in another struct

跟風遠走 提交于 2019-12-14 04:23:54
问题 I'm on prgramming a menu for an 16x2 LCD for a small arduino project. I'm nearly finished, but i do not understand the last small issue. The following (simplified) code generates the problem: int var1=0; int var2=0; typedef struct { unsigned int item_value; char item_name[17]; } Select_Item; typedef struct { char item_name[17]; int* variable; Select_Item* list; } Menu_Item; Select_Item sel_one = { 0, "Selection 1" }; Select_Item sel_two = { 1, "Selection 2" }; Select_Item* sel_list[2] = {

SD.open() returns true but does not create a file

久未见 提交于 2019-12-14 04:05:14
问题 I'm facing a specific problem with SD card and Arduino. I want to create a function that creates a new file on the SD card for a different day. For now, I'm simulating calendar with ints. I know that problem was already discussed but I can't seem to find a similarly discussed problem. Code: #include <stdlib.h> // included for floatToString #include <math.h> #include <SPI.h> #include <SD.h> int year = 2014; int month = 11; int day = 4; char dateTitle[20]; //= "0000000000.txt"; void

How to plot a room outline from range finder sensors in a toy car?

荒凉一梦 提交于 2019-12-14 03:42:44
问题 I have a toy car that has an arduino and 4 Ultrasonic Range Finder sensors in front, rear and both sides, they give me the distance to a wall if any exist within the range that the sensor covers, the sensors give me this data in short intervals, the car has to move around a room and plot the outline, the rooms can have columns and be kind of irregular, I don't know the algorithms involved in this plotting, any insight would be appreciated. 回答1: heh once did a robot that was almost the same :)

Can someone please explain this line

北城以北 提交于 2019-12-14 03:36:01
问题 K_count = (K_count < (byte)(CharacterMask[0][(customKey - '0') - 1][0]) ? ++K_count : 1); It is a part of this simple code, and i cant understand how precisely does it work? 回答1: this basically increments through the available options on a standard US telephone keypad for the "3" key, looping back to the first option after the last is reached. it does so by referencing a 3-dimensional array containing the options for each key layed out as row/column/options. it is written in such a way that

send SMS for 1 time with arduino GPRS SIM900 if an iput is HIGH

不羁岁月 提交于 2019-12-14 03:19:57
问题 I faced a problem to send 1 SMS if an input is HIGH,and if it is LOW==> no SMS to send,if LOW to HIGH==> send 1 SMS. this code not working,just sent SMS when I turn the GPRS on,and after nothing is happened. mclopez helped me,thank you,but not working :( , this is the new code that I wrote with the delay()s,but the same problem. Thank you for helping in advance. #include <SoftwareSerial.h> #include "TimerOne.h" const int DI = 2; const int DT = 3; const int DGP1 = 4; const int DGP2 = 5; const

Arduino code to write and send at the same time simultaneously

余生长醉 提交于 2019-12-14 02:46:00
问题 I am working a graphical blocks for Scilab (software similar to MATLAB) simulation environment. There should be blocks called AI (analogue input), AO, DO. Also, there will be two programs: 1) on the side of Scilab, one which sends and receives data; 2) on the side of Arduino, one which sends and receives data. Right now I am working on Arduino side code. It, the code, should read voltage values from 6 inputs and sends them to Scilab via serial and simultaneously write 1/0 to its outputs when

Attempting to use a Template instead of an Overloaded Function in Arduino: TYPE not declared in this Scope

走远了吗. 提交于 2019-12-14 01:22:53
问题 I'm trying to write a function that can Shift out data to 74HC595 shift registers which can shift out 8, 16, and 32 bit values. Using an overloaded function, I have this: /********************************************************************************** * Software SPI Pin Settings *********************************************************************************/ #define SPIPINPORT PORTB //The Port that the Pins are on. #define LatchPin 2 //_RCLK Shift register clock pin #define DataPin 3 /

Calling nest API from Arduino

半城伤御伤魂 提交于 2019-12-13 23:58:33
问题 I am trying to call an nest api to get room temperature using C code in Arduino. When I call the api using postman, I get perfect response: However when I write the code to get the temperature data, I get the following response: request sent The request is HTTP/1.1 400 Bad Request. Here is my code, can anyone help me what's wrong with my request: const char* ssid = "linksys"; const char* password = "XXXXX"; const char* host = "firebase-apiserver07-tah01-iad01.dapi.production.nest.com"; //

Arduino - detecting motion/movement?

为君一笑 提交于 2019-12-13 21:16:01
问题 I need to detect in which direction the item is moving. I want to know if the item is moving up or down. Is this possible with this platform and by using a specific shield? I had in my mind the ultrasonic sensor, with which I would measure how far the item is from a certain point, and with this suggest what type of movement is happening because of the distance changes. I think this might be tricky, and wanted to see if there are better alternatives. UPDATE: I updated the question, corrected