New answers tagged

0

Yes. Linear Acceleration at given axis = Actual Acceleration - Gravitational Acceleration Gravitational Acceleration across any Axis = Magnitude of Gravity Vector x Cosine of axis angle with the Gravity Vector


1

In this line: SCENARIO btns[4] = { _red, _yellow, _white, _stop}; you are making 4 copies of the structures and placing them in an array. Instead you should either create the array directly with the values: SCENARIO btns[4] = { {-1, -1}, {-1, -1}, {-1, -1}, {8, 4} }; And only use the array, or use pointers in the array: SCENARIO *btns[...


1

The problem is that a struct is handled as a value type, not as a reference type. This means that a copy of _stop is made and put in btns (btns[3] actually). So what you need to do is putting pointers into the btns array: SCENARIO* btns[4] = { &_red, &_yellow, &_white, &_stop}; The symbol * denotes a pointer, and & means the address ...


1

"Pseudo-code" isn't a programming language. It is just a term that we use when we write code that looks like code but can't be compiled, because it's half-English, half-code. You write pseudo code when you want to communicate to another human how code is supposed to work without getting bogged down in the details.


3

analogRead() returns 0x0000 to 0x03ff If the max data 0x03ff is shifted to the right by 3 bits (or divide by 8), then 0x03ff becomes 0x007f, or 127. I think this will do it: desiredMax = analogRead(A0) >> 3; // divide 1023 max by 8, becomes 127 max


2

You can use the map function, see https://www.arduino.cc/reference/en/language/functions/math/map/. Example: If your pot meter gives values from 100 to 1000 and you want to map that range to a range of 0 to 128 you can easily write: potValue = map(readValue, 100, 1000, 0, 128); High likely, in your case and if the potentiometer is 'perfect' it returns ...


2

(Answering in more detail, as this is the top search hit for "ESP8266 Vin", at least for me) TL;DR: Vin is NOT directly connected to USB power. There is a protection diode between USB+/VU and Vin, which has a limited current capacity. If your board provides VU, that one is directly connected to USB power. As long as you only power 1-2 tiny devices, it ...


1

CS12 has a value of 2 since it represents bit 2 of the TCCR1B register. (1 << CS12) takes the value 1 (0b00000001) and shifts it left 2 times to get (0b00000100). The order of operations dictates that things in () happen first, so this is done before the "|=" is evaluated. (1 << CS10) takes the value 1 (0b00000001) and shifts it left 0 times ...


0

To elaborate on Majenko's answer, you can create some enumeration types for the states, e.g. enum EAlarmState { On, Off }; EAlarmState _alarmState = EAlarmState::Off; enum EBlinkState { BlinkOn, BlinkOff, }; EBlinkState _blinkState = EBlinkState::BlinkOff; unsigned int long _lastBlinkTime = 0; The _blinkState and _lastBlinkTime state ...


1

Because you're using delay() within your while loop you have to ensure that you are pressing the key at the precise moment it is read. You should not use delay(). Instead take a look at the BlinkWithoutDelay example in the IDE. And also consider implementing a Finite State Machine to know both if you're blinking and what state you're blinking currently is ...


4

This manual page of strlcpy() is quite clear: If the src and dst strings overlap, the behavior is undefined. This means you should avoid it, even if it works on some tests. The advice you got of just trying is not good advice. Use memmove() instead.


1

Acceleration is a vector quantity. Therefore, instead of looking at the average values of X,Y, and Z, you should probably look at the magnitude of the acceleration vector, that is (X^2+Y^2+Z^2)^0.5. Then, you can set an acceleration threshold below which you would send no data. The benefit of using the magnitude of the acceleration vector is that it is ...


3

You can connect via: UART I2C SPI All are available on the Pi's GPIO header and on the Arduino. You will of course need logic level translation for a 5V Arduino. Using UART is probably simplest for you since that is identical to using the USB - you just use /dev/ttyS0 (or /dev/ttyAMA0 on older Raspberries) instead of /dev/ttyUSB0 or /dev/ttyACM0. Just ...


2

Here lies your ≈ ½ ms problem: #include <SoftwareSerial.h> SoftwareSerial is very time sensitive. It generates the serial stream by bit-banging, with interrupts disabled. For each byte sent, interrupts are disabled just before sending the start bit, and re-enabled just after the stop bit has been written. At 9600 bps, interrupts are thus ...


3

Two possible solutions: Split the serial string in small pieces so it's (comfortably) less than 50 ms and send the string in 'pieces' … you could even send it until e.g. 45 ms has been reached and continue in the next round. Use the Blink Without Delay mechanism to switch between the tasks. More robust solution: Make Task 2 an interrupt... This is probably ...


1

You can use the millis function to check the current 'time'. If you store this, and later call this function again, by subtracting you can see how much time has been passed. so instead of delay(500) you use if (millis() - timeStamp >= 500) { ... to continue your code. As others said in comments, you also need to debounce to prevent multiple button ...


1

You cannot pass an array of characters as an argument (implicit or not) to a function. When you write String rtcTimeString(char ts[] = "MM/DD/YY hh:mm:ss"); The array notation is implicitly converted to a pointer. The line above is then equivalent to: String rtcTimeString(char *ts = "MM/DD/YY hh:mm:ss"); And this is incorrect: you are initializing a ...


1

This basic C++ (and GIYF). What about String Esper::rtcTimeString(std::string dateTimeForamt = "MM/DD/YY hh:mm:ss") { DateTime now = rtc.now(); return now.toString(dateTimeForamt ); } See, for instance, this question. Hope this helps :-)


7

The problem is that float numbers are seldom an exact representation. So the float is stored as the closest number that is exactly representable as a float, namely 10446438 × 2−18 = 39.84999847412109375. When you multiply this by 100, you get 16322559 × 2−12 = 3984.999755859375. And than casting to an int or long results in 3984, not 3985. so whenever you ...


1

There are two issues at play here: 1 – Limited precision of the float data type A float has a precision of roughly 10−7, and any number that is not an exact float is supposed to be rounded to the nearest float. For example, the two floats closest to 1.234567 are 10356298 × 2−23 = 1.2345669269561767578125 and 10356299 × 2−23 = 1.23456704616546630859375. The ...


0

You get this, because a float uses a certain number of bytes (I don't have an Arduino at hand), I think it is 4 bytes. In these bytes, only a certain accuracy can be stored, so the least significant digits gets rounded (binary, resulting in different end digits). Only for e.g. Arduino Due: You can use doubles instead, see https://www.arduino.cc/reference/...


0

If you are using atof() to convert the string to a floating-point number, you would only get 6 or 7 digits of precision. And the numbers in your examples already have that much precision.


0

It seems that I must convert to string first then use atof.


0

I will skip the RFID part, that is unrelated to the menu. What you can do is creating two variables: int menuLevel1 = 0; int menuLevel2 = 0; Assuming you have 2 levels, if you have more levels consider an array. Now you can print the screen based on the values of these two variables (use a switch statement for menuLevel1 which calls new functions, each ...


0

For decent audio recordings, you need an external (16 or 24 bit, 44.1 KHz or more) ADC with at least two channels (stereo). To save it to an SD, you can buy a so called SD data logger, they are very cheap. Not all SD cards are compatible so you might have to try several ones. The protocol used is SPI.


0

If you look at the surrounding methods, you'll see that 'fadeToBlackBy' will give a fading effect on anything you feed in. You'll want to locate method 'beatsin16' and then edit it yourself so that it doesn't bounce back but restarts the counter at the first LED. (hint: phase_offset) You'll find the code snippet you want to copy in lib8tion.h /// beatsin16 ...


1

It depends actually on your requirements what is 'best'. If (transmission) speed is an issue, there are mainly some things you can do to improve this: Increase the transmission speed (this depends on the distance of the wires and the noise). Decrease the start/stop bits (this reduces the certainty the values will arrive ok) Pack your data (takes more ...


0

in loop() replace digitalWrite(led1,LOW); with if (newTime - oldTime >= dt){ digitalWrite(led1,LOW); } and you can remove the else if(oldTime-newTime >= dt){ oldTime=newTime; digitalWrite(led1,LOW); } from the for loop


1

Old time and new time are wrong way round on a part where the LED'd are switched off else if(oldTime-newTime >= dt){ oldTime=newTime; digitalWrite(led1,LOW); } When simple processors reach the max or min value and continue counting, they overflow and start counting from far end: So 5-8=maxint(largest number)-3 Result is that ...


1

In fact all the mentioned function calls are using the Special Function Registers (SFR) and thus the hardware peripherals of the Arduino in the background to work. But I guess this is an exercise to learn how to configure and use these peripherals yourself. Doing this for the whole code is a rather big task for a single question on this site. So I will give ...


1

I don't think anything in your code is going to work. First, you are asking the serial.Read to return an integer if it is working. You might want to change that to a Boolean. Second, You are asking for a 1 and only a 1 to make your next if statement true. If the serial.Read is working the chance it will only return a one, I think is very low Third, On ...


0

Definitions via #define don't use equal signs. The following is wrong #define EN = 1 Instead it should be #define EN 1


0

I would consider using HoodLoader2 instead of that LUFA project. If you can't do that, you can compile parts of the Arduino Core together with the LUFA project. The main steps: Add the necessary Arduino source files to the SRC variable in the Makefile. Add the Arduino core folder to the include path by appending to the CC_FLAGS and CXX_FLAGS variables. ...


Top 50 recent answers are included