New answers tagged

0

This is pretty simple, although you shouldn't see any difference, because loop() is running a lots of times in one second. But: bool firstrun = true; void loop() { if(firstrun == true){}; else{ if(digitalRead(switch_pin) == LOW){ digitalWrite(led_green_pin,LOW); digitalWrite(led_red_pin,HIGH); lastMotionState = currentMotionState;...


3

The following code will pause (Give some delay) when it runs for the first time and also when you press the button. int status = true void loop() { if(status){ //Pause delay(15); status=false; continue; } if(digitalRead(switch_pin) == LOW){ digitalWrite(led_green_pin,LOW); digitalWrite(led_red_pin,HIGH); ...


1

You are on the track, but it needs some adjustments: template < typename datatype> class Device_Handler { // a class to handle devices public: virtual void write_to_device(datatype *send_data)= 0; // write data to device virtual void read_from_device(datatype *store_location)= 0 ; // read data from device to location ...


3

There's two problems here. First, you don't enter "234", you enter "2" followed by "3" and finally "4". Your really small timeout doesn't give the digits enough time to arrive. Second, your line ending is being received and interpreted as "not a number" which is returned as 0 by .toInt(). What you need to do ...


3

There are a couple of issues here. One of them has already been raised in a comment: int main() { - ddrB = (port_type) 0x20; + *ddrB = (int8_t) 0x20; while(true) { The more serious issue is in the command line you used to compile the program. When compiling for an Uno, you should add the option -mmcu=atmega328p. This way the compiler ...


0

The question was answered many times before, but you can convert an String to Integer either by converting it to an char array and using the atoi() function: char strVal[10]; str.toCharArray(strVal, 10); int val = atoi(strVal); or simply using the toInt function: int val = str.toInt(); Source: Arduino Forum EDIT: Try to use the second solution as the atoi()...


1

The C library function atoi() will do that for you


1

timestamp in rtcReadTime() is a local variable. When you return from that function it ceases to exist - so what you have returned is nothing. You can't print nothing, so the Arduino crashes. You either need to make the timestamp variable static so that it's not lost when you leave the function, make it a global variable, which has a similar effect, or pass a ...


4

Your breadboard is one of those which have the power/GND lines interrupted between columns 31 and 33. I also once fell into this trap. If you look closely, you see that the blue and red lines are interrupted in the middle of the board. Just put wires between these pins to bridge the gap.


0

Start by writing a sketch that debounces your buttons to get an accurate count of each button press. Install the Bounce2 Library available in the IDE. Use a byte array to store the sequence of button presses (record the pin numbers). Once the pre-set limit (sequence length) is reached, play back the sequence. Playing back the sequence could look something ...


1

You are wrongly using the new operator for your arrays. That will dynamically allocate these arrays. They are put on the heap (not the stack like local variables) and thus don't get freed automatically, when the function exits. That has to be done by your code with the delete keyword. Your code just eats up all the available memory. Thats called a memory ...


3

It's working as intened. The arduino UNO has no DAC (digital to analog converter) onboard, so all it can produce are digital signals, either 0 or 5v. The analogWrite function uses Pulse Width Modulation to produce an output that, on average, has the requested voltage, by quickly alternating between logic low and high with different durations. This is done at ...


2

I don't quite understand the code snippets, that you added to your question afterwards (they are partly incomplete). But I will propose my own solution to the problem. A melody is a list of notes and pauses. Each note has a pitch and a duration. A pause has only a duration. We can now define a struct for holding a note: struct Note { unsigned int pitch; ...


1

You check StickMan and Object only X position not check Y position incase you can check StickMan Y or check StickMan action like this code below. or try this sim https://www.tinkercad.com/things/1LiyoY5n1mS-copy-of-stickman-rush/editel?sharecode=X6rMj1GjrKoAH95qWKY21z98ttyAs5aOTAKYy6hVJ3c // Defind it on top bool stickManIsJump = false; // Added some code ...


1

In essence you will need to break your for loop open and use a global variable for thisNote, incrementing it each loop (with the millis example so that proper timing is still adhered to). This isn't the only approach to this problem. Your existing code could check for the button press within the for loop and escape the for loop when pressed.


Top 50 recent answers are included