C++ :: Sensor Values Reading Wrong
May 26, 2014
I am only receiving the correct temperature value. The other 3 values are reading wrong. My format string isent matching the variable list. What I need to do.
float data_bar = 0.0;
float data = 0.0;
float anVal = 0.0;
float moistureVal = 0.0;
while(1) {
// Get the new value using the get() function
[Code] ....
View 3 Replies
ADVERTISEMENT
May 24, 2014
My whole code is working but when the results are sent to my phone only the temperature value is reading correct the light value is all jungled up and moisture and pressure values are reading as 0.
Code:
#include "taskFlyport.h"
#include "grovelib.h"
#include "barometer.h"
#include <string.h>
extern BOOL incomingSMS;
extern int incomingIndexSMS;
extern BYTE incomingMemSMS;
[Code]...
View 4 Replies
View Related
Jan 19, 2015
I have been experimenting with a program that loads WAV file and tries to read 1s and 0s from audio file (binary coded information). So far I got working code, but the problem is that I'm not getting correct data. I do get somewhat similar data. The problem is that I get data that amplifies low amplitudes, so instead some noise and binary data I get lots of noise and hard to recognize binary data. My code is this
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
// An unsigned char can store 1 Bytes (8bits) of data (0-255)
[Code] .....
This is wav file in binary viewer (after header)
0030 0032
00300035003200320035003A0048004A
004C0049004A00510049004300360038
and translated to decimal
48 50
4853505053587274
7673748173675456
and this is output from "wavosaur" program (and this one is correct)
0.001465
0.001526
0.001465
0.001617
0.001526
0.001526
0.001617
0.001770
0.002197
0.002258
0.002319
0.002228
0.002258
0.002472
0.002228
0.002045
0.001648
0.001709
You can see it's not the same. I do get the same data like I do from binary viewer, but I don't understand how they are translated to amplitude value. ? Where is the catch?
So this is not really question about c++, but about wav file structure and reading data.
View 2 Replies
View Related
Jun 7, 2014
I have a game that requires the switching of tiles. When I try to switch the blank tile (_) with 5, the 5 switches with the 8 instead of the tile switching with the blank tile. The code behaves the same with top row. I have observed that this only happen in the row and column bound by [0][0]; For example the four top left tiles ([8, 7, 5, are 4]) are behave erratically.
Here is sample code!
//swap if columns are equal and blank is to bottom
else if ((blankCol==tileCol) && (blankRow-tileRow==1)) {
temp = board[blankRow][blankCol];
board[blankRow][blankCol] = board[tileRow][tileCol];
board[tileRow][tileCol] = temp;
return true;
}
I am thinking perhaps there may be a double switch but then again why does it for only the left column and top row.
Attached image(s)
View 2 Replies
View Related
Mar 6, 2015
I am about to transfer a project I have written in Applescript and Objective C to Excel/VBA/dll. I have started with the Objective C functions that I want to place in a dll and call via VBA.
The Objective C is C with a thin dusting of special Obejctive C code to have it talk with Applescript and the rest of the project so in theory it should be easy to make dlls written in C from it.
But I have already problems with the tiniest of all functions. I am sure it can be done more effectively but right now I need to know WHY it doesn't work if I am ever going to be able to transfer the much larger functions from Objective C to C.
Here is my original Objective C code:
Code: -
(NSNumber *)game:(NSNumber *)games gamechange:(NSNumber *)gameskifte
{
int gamesab = [games intValue];
int gameskifteab = [gameskifte intValue];
[Code].....
View 5 Replies
View Related
Aug 19, 2013
I am working on a project with rf2500 radio sensors and a state machine handles the whole fucntion of the sensor.. I have this while statement
Code:
while(state!=STATE_STATENINETYFIVE){
__bis_SR_register(LPM3_bits + GIE);
__no_operation();
}
which stop the sleep mode of the CPU every time the STATE_STATENINETYFIVE comes up. I want to make it like this
Code:
while((state!=STATE_ABRRECEIVE)||(state!=STATE_STATENINETYFIVE)){
__bis_SR_register(LPM3_bits + GIE);
__no_operation();
}
So if STATE_ABRRECEIVE or STATE_STATENINETYFIVE comes up exit the while too.
I read some previous post about and I thought to change the logical OR || with AND && but din't work for me... state is type of u_int8_t. Is it a logical error???
View 4 Replies
View Related
Mar 30, 2014
This is a program that is for a robotic car. The car has two light sensors on the front to detect when it veers off the road. When a sense is detected on one of the sensors the corresponding motor will halt until the sensor again detects the track. Again two sensors, left and right, and two motors (one per wheel). I have case statements to do the two left and right sensors.
how would I implement a third sensor with an interrupt to halt the car after it senses a stoping line. E.g. the sensor in the middle detects the stopping point so both motors halt.Here is the code I have so far...The cases are the sensor detections.
Code:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
// Function Prototypes
void init_PWM(void);
void initLCD(void);
[code]....
}
View 4 Replies
View Related
Dec 22, 2014
I cant seem to read stuff in from my students.txt file which contains this
19992195 John Smith 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20051195 Mark Dobson 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20063196 Paula O'Reilly 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20053344 Aoife Cleary 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
It has something to do with the lines at the bottom of the code. It doesnt cout anything. The program just crashes upon execution. First, it asks me the amount of students i want to handle. I enter '1'. Then it asks me if i want to read in from external file and i enter 'Y'. then the exe just crashes
#include <iostream>
#include <cstddef>
#include <cstdlib>
[Code]......
View 3 Replies
View Related
Mar 14, 2013
After asking the user to input 2 values i expect my program to read them and then output whether they are equal, bigger or smaller than one another. However i am getting no output what so ever when i input the values
code below:
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <string.h>
using namespace std;
int intInput1, intInput2;
float floatInput1, floatInput2;
int x, n;
[Code] .....
View 1 Replies
View Related
Jan 21, 2014
My problem is that I need to take a csv or excel file with tens of thousands of datapoints, write all points in a section of column to an array, perform calculations on them, and then write it back into another column.
I've been looking all over the internet for ways to do this easily. So far I have not found anything that I can follow and implement.Some codes have been slightly useful, but they aren't commented in a way I can understand. How to write code to take, for instance, lines from column b between 500-1000, write them to an array, and write another array 500 characters in column c. If that code could be commented, I have tried a few different techniques (counting commas), but haven't gotten anything to work.
View 9 Replies
View Related
Oct 5, 2013
I have a .txt with a 0 or 1 to each line of the txt file. there are many values to read. I am reading the values and calculating how many each reoccur in a sequence (run-length encode). If i only use say 50 values coming in it works, but once i do the hundreds there are in the file it hangs. i am not sure why.
Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
FILE *infile;
FILE *outfile;
void PrintBinary(int x,int y);
[Code] ....
View 3 Replies
View Related
May 20, 2013
We are supposed to split this lab into 3 files a .h and 2 .cpp's. The code I'll be talking about is going to be directed at the main.cpp file. Basically we are supposed to be able to enter as many classes into the program and when you are done the program is supposed to save the contents into a .dat file. This lab is working off of an older lab so I already have a .dat file I am trying to test with this program by reading it into my program when I first run it I prompt if the user wants to load previously entered courses and if they reply with a 'Y' the program will load the contents of the .dat file. Problem is right now when I load from the .dat file only the first class is correct. Every other class after that is just giberish. I've tried everything but can't get the restore part working. I also cannot get the save to .dat portion of this lab working either.Here is my code:
#include "Course.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
[code]....
View 1 Replies
View Related
Mar 25, 2013
I am trying to read an array values from Tmin.txt file. I take array size from user viz. number of raw & column and then, read the following data from Tmin.txt file which look like this:
20 40 20 25 30
20 30 40 20 25
20 40 20 25 30
20 30 40 20 25
30 40 40 30 40
I am using getline, and then converting it to int by using atoi. But my code is not working.
Code :
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
[Code] ....
View 5 Replies
View Related
Apr 12, 2014
My game is a sort of RPG with stats, money etc. I just recently added a save/load system using writing to a file. I initially got writing to a text file to work, then I got loading to work too.I eventually was able to read numbers from the file and assign them to integer variables in order.
My issue was I wanted to check if a save file existed, if it did, load it up, if it did not, go to character creation. I had a lot of trouble with this and after trying different code snippets to work I finally got it to check if a file existed, and execute the appropriate code.
My issue now is my code USED to go through each entry and assign variables in order.
Like the first number in the text file would be for the variable money, and it would read it, assign to to int money and scroll to down to the next variable for player strength, assign to to playerstr variable and so on. After making the tweak for loading it no longer functions like this, and makes the last entry in the text file the value for everything.
Here's my code:
Save Code:
{
ofstream savegame;
savegame.open("C:/Sounds/savegame.dat", ios::trunc);
savegame << money << endl;
savegame << playerstr <<endl;
[Code]....
I barely get how this code works, how can I tweak it to go through the file in order and assign variables one at a time?
At the current moment, it assigned the playerstr value to both money and playerstr int. But the save file being created lists the correct values in order.
View 5 Replies
View Related
Dec 1, 2013
I am trying to read hex data from a file (not just hex values in text format). I was able to read it (02 EC) with "fread" into an char before but I need to change the Hex value into an integer in decimal.
I already read about strtol but I would prefer reading the hex Value into an integer.
Here is my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int itrack1[1];
int itrack2[1];
[Code] ....
View 11 Replies
View Related
Oct 11, 2013
I am trying to read the file which has the values stored in the following pattern
2 4 10 103 2 504 .... and so on
I Have opened the file and then passed the opened file to another function to process it further.
here is my code
#include <iostream>
#include <fstream>
#include <vector>
#include <stdlib.h>
[Code].....
now the problem is when the control exits the "while loop" in the function "readingValues(std::ifstream& myFile)it goes straight to catch block ?
View 9 Replies
View Related
Dec 11, 2014
I have written in a binary file using fstream an using sort value.
unsigned shortwidth=50,height=50;
file.write((char*)&width,sizeof(width));
file.write((char*)&height,sizeof(height));
When i try to read it back from fstream again there are some symbols (binary obviously). How can i get my values back? I want to read those symbols and in a way to convert them to my old width and height values.
View 6 Replies
View Related
Apr 22, 2012
Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.
The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.
What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?
Here is what I got
Code:
#include <vector>
typedef std::vector<double> Double1D;
typedef std::vector<Double1D> Double2D;
typedef std::vector<Double2D> Double3D;
#define HEIGHT 5
#define WIDTH 3
[Code]....
View 7 Replies
View Related
Jul 31, 2013
I just got a job programming a windows application. One of the requirements is reading and writing values from an excel spreadsheet. Looking online, it appears that C++ isn't the best (one of the worst?) languages for reading and writing values from excel files. Now the language I'm most familiar with is C++ and I've been looking at C#, and it appears to be much easier to read excel files.
View 8 Replies
View Related
Dec 26, 2012
I have problem reading CSV file, i found many solutions but i still got one problem. I need to read CSV file and then these values show in List Control and here i have problem. Idk how to display it in List?
View 4 Replies
View Related
Apr 4, 2014
I am attempting to read values from a file into a 2d array temp[31][2] (31 rows, 3 columns).I only want the values from the file to be read into the first two columns.I believe I am accomplishing that but when I go to print the array, I expect the first two columns to have the file data and the third column to have all zeros. The third column, however is printing such that the value is the next row/first column.
I'm not sure for instance why on the bottom loop for line 1 it doesn't print:
temp[0][0] temp[0][1] temp[0][2] 20 49 0 It instead prints: 20 49 1
Code:
#include <stdio.h> Code: #include <math.h>
FILE *inptr;
int main() {
int temp[31][2] = {0}, tempavg[31][2] = {0};
int i, j, k, sum;
inptr = fopen("ProgrammingProject14.txt", "r");
[code]....
View 8 Replies
View Related
May 6, 2013
So I have this text file that I am trying to read from and store the values of each line in multiple variables.
Let's say my text file contains
AXSYZ3482 Tom 100 112
and my code below here works fine when the lines in the text file is separated by spaces.
while (fscanf(fp, "%s %s %d %d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}
But let's say my file was to look like this instead.
AXSYZ3482:Tom:100:112
But if i try this below...
while (fscanf(fp, "%s:%s:%d:%d
", userID, name, &startLoc, &endLoc) != EOF) {
printf("%s %s %d %d
", userID, name, startLoc, endLoc);
}
It seem to store the entire line in userID including the ":". I want to ignore the ":"'s and store everything in between in respective varibles in the order specified above.
So first string in userID, then ignore the :, then second string in name, and ignore the next :, and so forth. How I can accomplish this?
View 2 Replies
View Related
Apr 12, 2015
Im trying to read from a file, line by line, with no specified number of values in the file. Check out my code:
int main() {
string x;
ifstream fin;
int count = 0;
char ch;
fin.open("CWC_Master.txt");
if(!fin)
[Code] .....
Now, this works great! However, its skipping some lines. And I dont know why. For example: Lets say that the input file is:
superman toy
sm2335
19.99
batman toy
bm5532
25.99
aquaman toy
am6786
26.00
Where it should output the above, instead it outputs every other one. Like:
superman toy
19.99
batman toy
25.99
aquaman toy
26.00
How can I fix my code so that it SIMPLY(i say simply because I am still a beginner coder) can read line by line?
View 7 Replies
View Related
Nov 15, 2012
Consider the following:
Code:
float foo( float const *bar )
)
{
float temp;
temp = *bar;
...
}
Something I am noticing is that temp right after the assignment to *bar, is not the same value as *bar. This is for a project at work and the code runs on an embedded board with an ARM processor. I've copied the function into a standalone program for both Visual Studio and Code::Blocks and it works correctly there.
View 12 Replies
View Related
Feb 19, 2014
I'm writing a program that shows check fees for different amounts of checks. My other fees are showing up right but the .10 cents is not. It's showing up as .08 cents per check when I run the program.
Oh yeah the + 10 is for a $10 fee
Code:
else if (checks < 20 || checks >= 0) {
fee = .10 * checks + 10;
cout<< "Bank service charge for the month is $ " << setprecision(4) << endl;
}
View 3 Replies
View Related
Feb 11, 2013
For an assignment I have to create a random array of four integers, and then I have to allow someone to input up to ten guesses to guess the array in the correct order. I also need to be able to display whatever was generated by inputting -1. Finally, after every guess I have to tell the inputter how many of the guessed integers are correct and in the correct position, as well as how many integers are correct but not in the correct position.
So far I've been able to get the random array to generate properly, but inputting negative one has no effect, although if I input it four times in a row I get to my 'lose' condition. Also, it only seems to allow the user to input 4 guesses and not 10 before going straight to the 'lose' condition. I need to get these issues sorted out before I can move on to showing how many guesses are right etc....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time (NULL));
[Code] ....
View 3 Replies
View Related