New answers tagged

0

You can use a timer with prescaler set to 1 in combination with a counter module. Attach interrupts to the compare and the overflow events. In the corresponding ISRs you handle the counting... I have no example for you and it might be a bit tricky how to implement the ISRs, but it's possible for sure, as long as you count a reasonable amount of clock cycles (...


0

Define global vars befor setup() unsigned long timeStamp = 0; bool pauseOn = false; and use it void speelMelodie(int melodie) { if (melodie == 1) { for (int thisNote = 0; thisNote < 8; thisNote++) { int noteDuration = 1000 / noteDurations1[thisNote]; if (millis() - timeStamp < noteDuration && pauseOn == false) { ...


0

I'm not real clear on exactly what you want to have there, but here are a few ideas that may help: If you know what character you want, then just get it. Like if you always want the second character (I think this is what you need): void someFunc(char *p) { char secondChar = p[1]; Serial.print(secondChar); } If you just want the last character in the ...


0

Thanks for the help, this is my working code. I changed things to long, got rid of some long's, stopped passing variables, and forced number in sensorValue to be long. It now counts up and down were I set the potentiometer every minute. int analogInPin = A0; int analogOutPin3 = 3; long sensorValue; int i = 0; int a; long y; void sens(){ sensorValue = ...


1

You define i,y,i as global variables so there is no need to hand them over to different functions. They can be accessed and changed in all parts of your program. define instead of int y; change to long y; and change void inOut(int &i){ to void inOut(){ and remove return i;// Its a global var change the line unsigned long y = ((...


0

To the best of my knowledge, there is not. What you speak of is possible, but it must be done manually by counting cycles, and I suspect it wouldn't actually help you. (And then you get into CISC issues where instructions can take different amounts of time to execute, potentially depending on arguments. Arduino (the actual one) is kinda safe from that, but ...


1

I have a post about this problem. Basically you cannot attach a class function with attachInterrupt because of the hidden "this" pointer which needs to be supplied to a (non-static) class function, where "this" is the particular instance of the class. You can work around it like this: class myClass { static volatile bool switchChanged; // declare ...


0

Almost certainly not Compilers often optimise switch statements using jump tables. However the entries in the jump table basically make up a lookup table with 214 entries! So you don't gain anything. Some ideas for compression You can use bit packing If your numbers aren't 8 bits in size, you can pack them together. For example, if you have managed to ...


1

Normally it's suboptimal to reduce the speed of loop just to be able to count them. Apply the BlinkWithoutDelay principle instead (which is not about Blink, but about WithoutDelay)


1

for(int i=0; i < 9999; ++i) { if(i % 10 == 0) { //my actions on i = 0, 10, 20, 30 ... } }


1

214 is 16384 entries. Each entry takes 2 bytes. That's 32768 bytes. That's all the flash the ATMega328P has. The most efficient storage will be an array in flash, and that will take 100% of it. Using a switch will take more space. So in short: no. Just no. It won't work whatever you try. You need to come up with a radically different storage solution (...


2

Include Guards only protect against inclusion of a header file multiple times within the same translation unit. This is important. If you include a header file (1) in a source file, then include another header file (2) in the same source file, said header file also including the previous header file (1), then the include guard will perform its function. ...


Top 50 recent answers are included