im using an Arduino to take data from a sensor and display it on an led matrix. but it has room for five characters on each row but the sensor gives data with five or six characters. I need to shorten it so it will fit but I don't know how to shorten the number stored in a variable. im also not sure if I can directly send the number in a variable to the screen or if I have to say "put the first number here , then the second here, etc. can you do that outside of something like Matlab?
Please read and follow the directions in the "How to use this forum" post.
ok if everyone is just going to be mean ill have to look for help somewhere else, since im clearly not welcome here.
Who was mean?
According to the OP, everyone.
the guy who said "go read this post" instead of helping. most of that post had nothing to do with my question and I don't know what specific thing he's mad at me for so he basically just saying "go away, we won't help you "
most of that post had nothing to do with my question
The "How to use this forum" post explains how to post your code properly, which is required to understand what you are trying to do and what the problem might be.
It also explains how to post links to the devices you have, and how to describe the wiring.
The post explains how to ask intelligent questions. So far, you have not done well.
Until you understand these points, don't expect help from this forum.
I like the kitten pictures.
I didn't post those things because:
- theres no code so far, I don't even know if the Arduino ide can do what I want so I can't post the code for that, for all I know it may not exist.
- the devices and wiring involved aren't relevant because those are working properly, my question is a purely Arduino ide coding question.
Delta_G:
Nobody is mad at you. That post he pointed you to talks about how to ask good questions and gives tips for getting the most out of the community. Asking you to read the forum instructions is in no way "mean".Now let's take a look at your question and see why it might need to be improved in order to get any usable answers.
Which kind?
What sensor?
What kind of matrix?
5 or 6 characters about what? Are they all important? What kind of data is it? Can we just chop a number off? Do we need to do some math? Change units? You'v given us almost nothing to go on here except that you want to remove a character. That's simple, replace the last character in the array with a null and it's gone and your string now has one less character. Will that do what you want? Who knows because you have been incredibly vague with telling what you actually want.
Is it a number or a string representing a number? That makes a HUGE difference.
I have no idea what you mean by this last part. What screen? How are you sending it? What are you talking about here.
the Arduino is an Arduino uno
the sensor is a temperature, humidity, air pressure sensor (Adafruit BME 680)
the matrix is a matrix of leds like the ones used in signs
but what I was asking was if I can either round or truncate the numbers it gives so they fit, I can't fit 78.28 and have room for units so I need to trim the number to four characters. and its an actual number because I can use math to change it.
since I don't know if the led matrix setup can handle taking a variable and displaying the contents I was asking if its possible to pick out one number at a time and so I can manually have it say "display this number, then this number, etc"
Yes, you can shorten the number in many ways - sprintf, or by manually manipulating the number with math functions. Iirc, if the display implements the print/println functions I think you can even set the number of decimal places of a float to print...
But not seeing the code you're working with that reads from sensor and prints something to the screen, I couldn't give recommendation on which approach best suits your needs.
Delta_G:
What numbers? What data type?What do you want? Just the 78? Just the 28? What do you want to cut off? You have to be clear about this. What you want is certainly within the realm of possibility, but you have to understand that we haven't been thinking about this project. You're going to have to explain in detail what you want.
If you want 78 and some units, then look at dtostrf followed by sprintf.
If you have an integer and you want to remove the ones place then just divide by 10.
There are lots of ways, but it depends on what type of number in what type of variable you have.
I still don't know what you mean by this:
I don't even know what matrix you have or how it works or how it is used. They're not all the same you know.
Is it the same as the matrix that I have?If you are using print to send to the matrix, then it may be as easy as just using the second parameter to print for floating point type variables.
But who knows because you think those details don't matter and this is just a general arduino question. Well it isn't. Those details DO matter. And when you know enough to answer this question THEN you can tell me what data is needed or not needed to answer it. Right now you don't know that.
the data types I'm starting with are are temperature and humidity I want to shorten it to something like 77.9 instead of 77.98 so I can display 77.9F. and ill do the same thing with the other data types the sensor gives.
its this matrix Overview | RGB LED Matrix Basics | Adafruit Learning System
its displays using " matrix.print('7');" thats from the example code the library has. I not sure if I can say 'matrix.print(temperature);' to display the data stored in that variable.
thanks! that should work. I looked into the libraries and those variables are declared as "float"
Requiredusername:
im using an Arduino to take data from a sensor and display it on an led matrix. but it has room for five characters on each row but the sensor gives data with five or six characters. I need to shorten it so it will fit but I don't know how to shorten the number stored in a variable. [...]
You can see arithmetic manipulation in the following codes where the floating point number 89.34 (current room temperature in 0F) has been transformed into 8934. Now, you have the pure binary value for 8934 in a variable; you can display 89.3 or 89.34 on Led-Matrix/7-segment/any_irregular Display Unit. (The codes are tested using BME280 Sensor and BlueDot_BME280.h Library.)
#include <Wire.h>
#include "BlueDot_BME280.h"
BlueDot_BME280 bme280 = BlueDot_BME280();
float fTemp;
void setup()
{
Serial.begin(9600);
bme280.parameter.communication = 0; //Choose communication protocol
bme280.parameter.I2CAddress = 0x76; //Choose I2C Address
bme280.parameter.sensorMode = 0b11; //Choose sensor mode
bme280.parameter.IIRfilter = 0b100; //Setup for IIR Filter
bme280.parameter.tempOversampling = 0b101; //Setup Temperature Ovesampling
bme280.parameter.tempOutsideCelsius = 15; //default value of 15°C
bme280.init();
}
void loop()
{
Serial.print(F("Temperature in Farenheit:\t\t"));
fTemp = bme280.readTempF();
Serial.println(fTemp); //89.34 degF
fTemp = (float)fTemp * 100;
Serial.println(fTemp); //8934.00
int intTemp = (int)fTemp;
Serial.println(intTemp); //8934
delay(1000);
}
Requiredusername:
im using an Arduino to take data from a sensor and display it on an led matrix. but it has room for five characters on each row but the sensor gives data with five or six characters. I need to shorten it so it will fit but I don't know how to shorten the number stored in a variable. [...]
Requiredusername:
I want to shorten it to something like 77.9 instead of 77.98 so I can display 77.9F. and ill do the same thing with the other data types the sensor gives.
The OP wants to shorten the numbers from 4-digit to 3-digit. I have just shown a way to do it. There could be much better way to do it.
The first page of this thread reminds me of this joke:
This is at the ticket window of a train station.
Customer: "One ticket, please."
Attendant: "One ticket to where, sir?"
Customer: "Don't be so nosey. Just get me that ticket!"
jremington:
This post is as relevant as my post. But mine got deleted. You guys have too much power!
You guys have too much power!
Only moderators can delete posts. Perhaps that kitten was too cute to delete.