Skip to main content
12 votes
Accepted

delay(time); vs if(millis()-previous>time); and drift

There's one important thing that you need to remember when working with time on an Arudino of any form: Every operation takes time. Your foo() function will take an amount of time. What that time is, ...
Majenko's user avatar
  • 106k
9 votes
Accepted

Why is this looping?

This line: if (legThreeBrightness = 255){ assigns the value 255 to legThreeBrightness. That is non-zero so it enters the block and runs the fade now that the variable has been set to 255. If you ...
Delta_G's user avatar
  • 3,391
7 votes
Accepted

NodeMCU and expected ';' before wrong ' " '

In C you can not use quotation marks inside quotation marks (thus nested). Replace message2 += " <meta name="viewport" content="width=device-width, initial-scale=1">"; to message2 += " <...
Michel Keijzers's user avatar
7 votes

Multiple Wire.write() not working for Arduino Nano I2C

Important information: Wire.write() does NOT send anything over the I2C lines. It just puts the data into the libraries internal buffer. The actual transmission is then done by Wire.endTransmission(). ...
chrisl's user avatar
  • 16.6k
6 votes
Accepted

Why are the Do While loops not stopping?

change >= and <= to > and < respectively. You want it to stop at 0, but your do-while will do another round, since 0>=0 is true. So your code only stops at -1 and 256. When ...
Gerben's user avatar
  • 11.3k
6 votes
Accepted

Measure Vcc on ATtiny13a?

The code you linked to measures the 1.1 V internal reference using Vcc as a reference. The ATtiny13A cannot do that. It does have a 1.1 V internal reference, but it can only use it as a reference for ...
Edgar Bonet's user avatar
  • 45.2k
6 votes

How to move a servo quickly and without delay function

The quickest way possible from LightON to LightOFF is simply servo1.write(lightOFF); without loops or delays, in one go; no need to do it degree by degree. For example: int lightON = 180; int lightOFF ...
ocrdu's user avatar
  • 1,795
6 votes

How do I make another action repeat inside a loop?

By using delay() it blocks the rest of the code. The programme needs to keep track of two buttons and update the lightshow at appropriate times, therefore a non-blocking style of coding is needed ...
tim's user avatar
  • 699
5 votes
Accepted

How to correctly use functions that return pointers to multiple typedef'ed types in Arduino IDE?

The Arduino IDE, rather annoyingly, tries to "help" you by generating function prototypes for functions, something it sometimes fails to do. You can make your code compile by adding one yourself: ...
Nick Gammon's user avatar
  • 38.9k
5 votes

Why are the PWM variables in this RC code snippet handled this way? What are the magic numbers?

There is not enough context to be certain, but given the variable names I can assume that this is code from a sketch that receives information from an RC controller and is intended to control parts of ...
Majenko's user avatar
  • 106k
5 votes
Accepted

Unwanted ghosting with charlieplexed LEDs

Charlieplexing code doesn't reset the state of unused pin and if the port value is HIGH + mode INPUT, it means the pull-up is enabled. Solution is reset all pins to LOW before code starts changing ...
KIIV's user avatar
  • 4,907
4 votes
Accepted

Code is not working (Matrix keypad)

Cited comment: Check pin modes. Should be INPUT_PULLUP and OUTPUT. Also, consider debouncing. – Mikael Patel Please, try: const char keymap[4][4]={ {'1','2','3','A'}, {'4','5','6','B'}, {'7',...
AltAir's user avatar
  • 542
4 votes

Variable declaration inside main loop

Michael's answer was good, as usual. Let me give you some more background though: In C/C++ (And in most modern languages) variables have a "scope", or an area where they are defined. Global scope: ...
Duncan C's user avatar
  • 5,752
4 votes
Accepted

Make an LED Turn

You can try implementing a counter system in your Arduino program. For example, if this is your loop() function: void loop(){ int buttonState = digitalRead(1); // Give the variable buttonState the ...
Sony's user avatar
  • 110
3 votes
Accepted

Whats wrong with my code?

The errors are self-explanatory. You just have to read them carefully. ‘B54A3AC5’ was not declared in this scope The compiler doesn't know what "B54A3AC5" means. Nor do I, but I gess you may mean an ...
Edgar Bonet's user avatar
  • 45.2k
3 votes

Why can I measure two pins simultaneously?

https://github.com/thomasfredericks/Bounce2/wiki I'm not familiar with the Bounce(2) library, but looking at the above site, it looks like "fell" is more of an "instant" thing, where it isn't ...
computercarguy's user avatar
3 votes
Accepted

Why can I measure two pins simultaneously?

You can test it easily by calling the function twice directly after each other. If the first time a true is returned and the second time a false, the state is internally reset. But probably because ...
Michel Keijzers's user avatar
3 votes
Accepted

Arduino classes, can't get property value

When you put the type there, you are creating new variables. SO in your constructor: MKSStepperMotors(int dirPin, int stepPin, int enablePin) { int _dirPin = dirPin; int _stepPin = ...
Delta_G's user avatar
  • 3,391
3 votes
Accepted

Having trouble with 74HC595 and Uno

Serial.read() is going to give you ASCII codes. So when you send 1 from the serial monitor the Arduino receives 49. Note that the ASCII code for a digit is the same as the digit plus 48, so that ...
Delta_G's user avatar
  • 3,391
3 votes

I keep getting stray '/302'.

The Stray /302 is saying that the compiler found some random unicode character that it didn't understand. You should put your code into some text editor that will allow you to see the unicode ...
Delta_G's user avatar
  • 3,391
3 votes

Getting error ets jan 8 2013,rst cause:4,boot mode(1,6) wdt reset

Found a possible solution. I was facing with the same problem. Apparently this is a hardware stack overflow watch dog preventing malfunction. This may not apply to every possible scenario but I ...
James Brown's user avatar
3 votes

Arduino Uno "if" statement is ignored in code and halts execution when using Serial.ReadString()

Let's look at what this code does when you send "On": if (command=="On") { //Turn the MOSFET on digitalWrite(5, HIGH); } This will evaluate true so pin 5 is set to HIGH. ...
per1234's user avatar
  • 4,298
3 votes

Arduino pow() making 9's

pow() works with floating point numbers. Floating point numbers are just an approximation. You will very rarely get precise results using floating point numbers. Instead you could write your own ...
Majenko's user avatar
  • 106k
3 votes

Arduino pow() making 9's

I put this code into the IDE, and for n>=2, I got 99, 999, 9999 etc. The catch is that Arduino uses floating point arithmetic to implement the pow() function, and some of your values are being ...
user85471's user avatar
  • 836
3 votes

esp8266 WiFi Cannot Connect to a PHP Server

This line: if (client.connect(server,80 && LED == HIGH)) { is definitely not going to do anything useful. Nor is this line: else if(client.connect(server,80 && LED == LOW)) { In both ...
romkey's user avatar
  • 1,583
3 votes

Seeburg Consolette Jukebox

This answer only involves help for the first problem: The code is long because it can play 160 songs Also, you can align your code by selecting it and press Ctrl-K. I will go part by part to improve ...
Michel Keijzers's user avatar
3 votes

a code to implement a simple traffic signal and also display on LCD which color is ON?

Write a sketch to test your LCD. #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 4, 2); void setup(){ lcd.begin(); lcd.print("Hello World!"); } void loop() { lcd....
Dougie's user avatar
  • 290
3 votes

I get an error saying, "exit status 1 expected initializer before 'void'."

Functions must have a body. So instead of: void setup() You need: void setup() { // do nothing } You have other issues, for example this is not C++: int (n,i,j,result); That should be: int ...
Nick Gammon's user avatar
  • 38.9k

Only top scored, non community-wiki answers of a minimum length are eligible