me Anny here !! I want help plzz actually m going to make programmable dynamo graph .Its a weight machine with circuit and that circuit is interfaced through port to a computer
Now i have to create a program that show a graph between voltage and weight but how is the graph when we apply weight then it becomes oblique line and when weight becomes constant then it is straight line
Any idea any concept about program will be really appreciated
thank you!

Attachments New_Picture.png 26.43 KB

You should be more specific, what do you want your program to do? If it's to create a graph, your best bet would be to use a bitmap library. Here's a snippet I changed slightly so that you at least have a base to draw onto a bitmap. Actually drawing the graph is up to you, I'm just providing a base.

#include <windows.h>
#include <iostream>
#include <cmath>

typedef unsigned long ulong;
typedef unsigned short ushort;
typedef unsigned char ubyte;

struct Pixel {
   union {
      ulong rgb;
      struct {
         // r, g, b share same memory as rgb
         unsigned char b, g, r;
      };
   };

   Pixel() {
      // Automatically set pixel black
      rgb = 0;
   }

   // Init pixel
   Pixel(byte _r, byte _g, byte _b) {
      r = _r;
      g = _g;
      b = _b;
   }

   inline operator ulong() {
      return rgb;
   }

   // Set pixel
   inline Pixel &operator =(ulong _RGB) {
      rgb = _RGB;
      return *this;
   }
};

template<short _Width, short _Height>
struct Bitmap {
   // Pixels
   Pixel *pixels;

   // Dimensions
   short width;
   short height;

   // Init
   Bitmap() {
      width = _Width;
      height = _Height;

      // Allocate Pixels
      pixels = new Pixel[width * height];
   }

   // Destroy
   ~Bitmap() {
      // Free all pixels
      delete[] pixels;
   }

   inline Pixel &operator()(short x, short y) {
      // Returns reference to pixel
      return pixels[(height - ++y) * width + x];
   }

   void save(const char *_FileName) {
      // Function to save as bitmap (no compression)
      BITMAPINFOHEADER bmpInfoHeader = {0};

      // Properties
      bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
      bmpInfoHeader.biBitCount = sizeof(Pixel) * 8;
      bmpInfoHeader.biClrImportant = 0;
      bmpInfoHeader.biClrUsed = 0;
      bmpInfoHeader.biCompression = BI_RGB;
      bmpInfoHeader.biHeight = height;
      bmpInfoHeader.biWidth = width;
      bmpInfoHeader.biPlanes = 1;
      bmpInfoHeader.biSizeImage = width * height * sizeof(Pixel);

      BITMAPFILEHEADER bfh = {0};
      bfh.bfType = 0x4D42;
      bfh.bfOffBits = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER);
      bfh.bfSize = bfh.bfOffBits + bmpInfoHeader.biSizeImage;

      // Create File
      HANDLE hFile = CreateFile( _FileName, GENERIC_WRITE, 0, NULL,
                        CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

      // Failed
      if (!hFile) {
         return;
      }

      DWORD dwWritten = 0;
      WriteFile( hFile, &bfh, sizeof(bfh), &dwWritten , NULL );
      WriteFile( hFile, &bmpInfoHeader, sizeof(bmpInfoHeader), &dwWritten, NULL );
      WriteFile( hFile, &pixels[0], bmpInfoHeader.biSizeImage, &dwWritten, NULL );

      CloseHandle( hFile );
   }

};

int main() {
   std::cout << "Generating Graph...\n";

   // Make Bitmap Object
   Bitmap<500, 500> bmp;
   
   [B]// Draw your graph to the bmp object here[/B]
   
   // Save to file
   bmp.save("graph.bmp");

   std::cout << "\nSaved BMP \"graph.bmp\".";

   return 0;
}

That's the hard part done, if you decide to use it.

Next would be to get input from the user (Voltage and weight) in order to actually have any data to draw.

Hope this is what you're looking for :P

I you want to draw a graph on the screen, you could simply make use of a graphics library (for instance Allegro, actually a game library but it supports simple operations like drawing lines (what you need if you want to draw a graph)) ...

On the other hand, you could take a look at William's post, but if it has to be platform independent you could make use of wxWidgets (which also supports some draw operations) or maybe even SDL ...

If you were more specific we could give you better answers to your question ...

Edit:: Allegro is also platform independent ...

Actually i want to make a program that takes max 5 reading from my circuit and plot a graph between weight and voltage on C++ output screen .I use ADC in my circuit now when a person stands on that weight machine then its scale changes which changes the potentiometer in weight machine due to which resistance and voltages will be changed . Now the program u posted is of very high standard still we r not that much familiar with C++ so I have to make a program of my caliber .As I draw a graph is like when a person stands on weight machine then values stars changing both of weight a voltage now this is shown by oblique line .suppose If 40 kg person stand on weight machine then my graph goes upward oblique and then become constant like straight now if i add more 10 kg weight with that 40 kg then after the constant line my graph goes again little bit upward as i shown in graph the obviously it again become constant like straight line.
PLZ if u can give me any idea or not getting my point then u could ask me thank you

I've made a graph class in wxWidgets a while back. You could have a look at it and modify it to fit you needs/

And don't post in italic-bold. It makes your posts annoying to read.

I've made a graph class in wxWidgets a while back. You could have a look at it and modify it to fit you needs/

And don't post in italic-bold. It makes your posts annoying to read.

Agreed, posts in italic bold are indeed very annoying to read ...

That's a good snippet niek_e.

To the OP, you might want to consider using a more userfriendly language to print/plot graphs, maybe dotnet, or java.

I say might cautiously, as your intention may be to reduce the bloat if you're communicating to a port and circuit.

so according to your scenario first decompose your scenario.

Think your computer is an isolated black box and you reading that
voltage using a port. Then the port is probably your serial port or
the parallel port , if you have A2D converter . if not you can use the
game port anyway most probablly you will end up with your sound
card gone( that's the only way to input analog thing to computer).


so you have a subroutine to just read the serial port or parallel port values and read the voltage. you'r A2D converter should
convert it to octal value or to the RS232 protocol. if you use the
serial port RS232 then you need a intermediate IC for that.

However using C++ access the serial port or parallel port is easy.
there are libraries for that.
http://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_port_Interfacing.html

so next task is to show that graph on the screen , yes you can
do that using a some free graphics library. like SDL.

need more information about what is your plactform ? what ports you going to use ?

ca u explain ho do i get connected with weight machine as u have created the graph so i thinking u must be knowing the setting ..i wants toconnect my weight machine with the pc so whatever weight on machine should be shown on pc...how can i retive the data of electronic weight machine to the pc....can u explain me plz
send me the information on my gmail id:
selfrules@gmail.com

This article has been dead for over six months. Start a new discussion instead.