Questions tagged [c]

C is a procedural programming language which is widely used in embedded systems. PLEASE NOTE: Arduino is typically programmed in C++, not C.

The C programming language is the (direct or indirect) predecessor of many modern programming languages, although it is still actively used and developed. It is very similar to C++, except that C is not object oriented. That is, it will only support simple data structures which have no member functions.

Note: Arduino is usually programmed in C++, not C.

Please do not use this tag to indicate a general programming question. You may want to consider using the tag instead.

429 questions
16
votes
6 answers

Arduino: How to get the board type in code

I want to write a sketch that can be compiled on different Arduino boards. I want to display on the PC which board is currently connected. This means that the user connects the PC via USB cable to the Arduino/Teensy board in which runs my sketch and…
Elmue
  • 481
  • 1
  • 3
  • 10
6
votes
3 answers

"EVERY_N_MILLISECONDS"

One of the FastLED examples that I've seen was using code that looks like this: EVERY_N_MILLISECONDS( 300 ) { transition_step(); } I've copied it and successfully used it in the same context - but I have no idea what it is or how it works. A…
Lefty
  • 325
  • 2
  • 4
  • 11
5
votes
1 answer

Chain of, or one big if sentence

(This might be more of a common C question) I want to test several conditions in an IF-sentence if(variable) { // fastest check if(register) { // a bit slower if(read_peripheral) { // very slow check // [do…
4
votes
3 answers

Using an external header file

I have a project that is part of a larger repository, and shares header files with non-Arduino C programs. I know that it's possible to use these headers by copying them to the libraries folder, or the sketch folder, but I would rather use them with…
Photon
  • 163
  • 2
  • 6
4
votes
3 answers

Arduino port relocation (PORTD to PORTB)

So I'm trying to connect the chip with an 8-bit data bus. All works good, but... Arduino Uno uses D0 and D1 for serial TX/RX (USB connection with PC). When I try to open a serial connection (on serial.begin stage) ports D0 and D1 blocks and the chip…
Thane Krios
4
votes
2 answers

Arduino Interrupt Debouncing

I have an issue with debouncing. I am using a MCP23017 as an I/O-extender with an Arduino. This uses I2C to communicate with each other. A variable amount of switches is connected to the MCP23017 (0-16 switches). On change of the inputs, an…
jdepypere
  • 153
  • 6
3
votes
1 answer

Knowing the Arduino memory capacity

I am using Arduino uno. My data is storing into EEPROM whenever i run my program, it will store multiple data depend on the loop. For my program it calculate 10 sample in 0.1 sec, so 100 sample in 1 sec. How can i know how much memory i can run? I…
Fufu Alex
  • 31
  • 1
2
votes
3 answers

Comparing a char with the symbols '.-'

I'm using the Arduino software to create a Morse code decoder using the serial monitor. I enter a Morse code such as .- as a text string and it's displayed in the LCD as a alphanumeric text. So if I enter .- into the serial Monitor, A is displayed…
user3485301
  • 33
  • 1
  • 3
2
votes
1 answer

How do I directly access a memory mapped register of AVR with C

Assume I want to write the following without using DDRD or PORTD: #include #include int main(void) { DDRD = 0xFF; PORTD = 0xFF; } I found this link which includes a list of mapped registers to memory…
Joes
  • 21
  • 1
  • 2
2
votes
0 answers

One of my my buttons is interfering with the other (i think)

So for school i have to make a code for my arduino, that let's me turn 4 led's on and off (as an input) with 2 buttons (one to select the led, one to toggle the led), run the inputs trough a logic circuit and based on the output toggle a fifth led…
Advanzd
  • 21
  • 2
2
votes
1 answer

Using map for DC motor instead of servo

I am trying to use map command which is used to power servo 180 degrees as the potentiometer moves... in fact what i want to do is just when i adjust my potentiometer to zero; stop the dc motor then after turn the pot to 512 analog value turn the…
mohammad
  • 21
  • 3
2
votes
0 answers

Sending variable in url

Working on a arduino code, but its C code. Having the problem that I want a variable with int to increase in a loop to run with the url: student.cs.hioa.no/~s180343/updatedb.php?verdi=%d The updatedb.php files takes the parameter and saves it to…
user3270211
  • 129
  • 1
  • 2
1
vote
1 answer

How to prevent Arduino compiler from merging changing of port pin outputs into a single operation

I want to set one pin's output value, and then set a different pin's output value so that the two pins change value one after the other. However, the compiler optimises the two calls to change both pins in one go. PORTD |= _BV(0); //set pd0 to…
mackenir
  • 113
  • 4
1
vote
3 answers

Code for a rolling average

Below is some code I wrote to find the rolling average of a temp sensor hooked up to an arduino and display it to an lcd display. My issue is that for the first minute it is running, the average is not correct. It starts at 0 and then progresses up…
Galen Kramer
  • 11
  • 1
  • 2
1
vote
1 answer

How is a long int stored in an 8 bit Arduino register

Assume the following code in C: long int a = 262143; which in binary will be 111111111111111111 (18 bits). If an atmega328p register can hold 8 bits, how is the above represented in the register? Compiled Assembly: .file "a.c" __SP_H__ =…
Josh l
  • 11
  • 2
1
2 3