10

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, we cannot say. The most reliable way of dealing with time is to only rely on the time for triggering, not for working out when the next triggering should be....


6

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 += " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"; By using the escape character \ it means that \" is a character (") instead of ...


5

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: typedef struct { int x1; } x; x *a; x *f(void) { return a; } typedef struct { int y1; } y; y *b; y *g(void); // <------------------ ...


4

You can't add a string literal and a number together. Instead you either have to convert one or both into a format that can be joined, or just treat them as separate entities. The simplest way is: Serial.print(F("The Conductivity Is: ")); Serial.println(voltage). Note the use of F(...) around the string literal - that forces it to stay in Flash so it ...


4

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 hexadecimal 32-bit value. If that's the case, write it with the prefix "0x", as in 0xb54a3ac5. ‘redpin’ was not declared in this scope Same thing, it ...


4

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 = stepPin; int _enablePin = enablePin; You start by creating three new variables with the same names as the member variables defined in the class. Throughout ...


4

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 sets bits 4 and 5 high. You can use Serial.read() - '0' to get the actual number from the ascii code.


4

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','8','9','C'}, {'*','0','#','D'} }; const int rpin[]={9,8,7,6}; const int cpin[]={5,4,3,2}; void setup() { Serial.begin(9600); Serial.println("Program ...


4

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. if (command=="Off") { //Turn the MOSFET off digitalWrite(5, LOW); } This will evaluate false so the else clause is executed: else { ...


4

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 truncated as ints. If you change: int multiplier = pow(10,power); to float multiplier = pow(10,power); The results should be as expected. (The brief reason ...


3

The first step with combining any programs together is to forget about combining programs together. Instead you need to do something completely different. Analyse the existing programs individually. Work out and learn exactly how they work and how they do what they do. Then think about your program. What do you actually want it to do, and how does that ...


3

1-) Isn't int mySensVals[6] = {2, 4, -8, 3, 2}; wrong? I count 5 elements. No, not wrong at all. There are 6 elements (as the definition says), and the first five are set to 2, 4, -8, 3 and 2. The sixth is undefined. 2-) Isn't char message[6] = "hello"; is wrong as well? I count 5 elements. No. There are 6 there. To quote your quote: Note that when ...


3

I suggest you to modify the following lines of code to check which reading has issue. if (isnan(h) || isnan(t) || isnan(f)) { Serial.println("Failed to read from DHT sensor!"); return; }


3

That piece of "code" is, I am afraid to say, complete gibberish. Passed through Artistic Style to reformat it ends up with: { int index; pinMode(10, INPUT); //button input int checkInput(); if (digitalRead(10) == 0) { return 1; else { return 0; } } Starting from the top of the program the errors ...


3

It has nothing to do with the retun statements. You have to close each { with a }. you are missing one. { int index; pinMode(10, INPUT); //button input int checkInput(); if (digitalRead(10) == 0) { return 1;} else{ return 0; } }


3

You can use arrays to hold sets of row pin numbers or column pin numbers, which then allows use of for loops for pinMode() settings and for testing LEDs one after another, as shown in code below. Note, using enum { ... }; for integer-constant declarations is slightly more compact than a series of const int statements. When a constant name in an enum does ...


3

As Edgar Bonet pointed out, “chosenColor = 3 means 'let chosenColor take the value 3'”. That is, your potVal = analogRead(pot); chosenColor = map(potVal, 0, 1023, 1, 3); sequence may very well be working, but by the time you get to Serial.println(chosenColor); you have changed chosenColor to 3. First, the statement if(chosenColor = 1) {...} changes ...


3

Assuming you wiring is correct, the only mistake I could see is that your variable named "getting" used in switch is inside the if, and it should be at least in the same level of switch. Also, your resume needs to be inside the if. #include <IRremote.h> int RECV_PIN = 3; int green = 11; int blue = 12; int red = 13; #define code1 16582903 // Must ...


3

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 after you call the fell function, the internal state is reset, so after the call not a new fell has been happened. So store the return value of the fell and ...


3

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 characters and go find it. It will probably be a lot easier if you'll format that code instead of trying to cram it all in one line.


3

Your loop(): void loop() { Serial.println(String(WiFi.status())); if (WiFi.status() != 3) { WiFi.begin("VENTURE", "12345678"); //WiFi connection while (WiFi.status() != 3) { Serial.println("Waiting for connection"); } } else { // Other code... } } While waiting for the connection, you are creating String objects ...


3

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 little integer-based ipow() function.


3

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 lines you're take the logical AND of the number 80 and the result of testing the LED. Put the closing parenthesis in correct place: if (client.connect(...


3

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 it (leaving the manual work to you): Align code #define BREAKOUT_RESET 9 // VS1053 reset pin (output) #define BREAKOUT_CS 10 // VS1053 chip ...


3

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: Variables declared at the top level of your program have global scope, and exist for the life of your program. These variables are usually created on the .data ...


2

Problems with your setup: Your pump is connected to pin 11 but you are controlling pin 13 (int led = 13;) You have an LED in line with your transistor base. That should be a resistor, and the LED should be in parallel with the base (with its own resistor). Your transistor is wired wrong. According to the datasheet the pins are C-B-E as viewed from the angle ...


2

How do you improve your code? Firstly there is nothing disastrously wrong with you code, it could do with a polish, but who's code couldn't? In the dim and very distant past I was told "you write code once but read it many times" so try and make your code readable and clear. If the values aren't going to change then they should be constants or #defines. ...


2

The idea to embed both setup() and loop() with an OOP instance is good, but why not pushing the use of class JKMotors and class JKMain deeper by removing static variables and functions. Step1 - use a JKMotors * in a non-static class JKMain: The default constructor JKMain() is just used to initialize motors. class JKMain { JKMotors *motors; public: ...


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