Page 1 of 1

C-code analog input

Posted: Wed Dec 05, 2012 11:52 am
by Dirk-Jan
Hello everyone,

For school I am supposed to translate a program I wrote to c-code and put it in a c-block in flowcode and it has to run exactly the same.
The problem I am facing is the fact that I need to make a keyboard where each key gives a different voltage to a analog input in the board.

This isn't that much of a issue in flowcode itself cause then you can just add a component macro to read the input as a byte and store it in a variable.
I need to achief the same functionality but then in a C-block.

Does someone knows how to achief this?

Note: I am using flowcode v4

Thanks!

Re: C-code analog input

Posted: Wed Dec 05, 2012 11:56 am
by Enamul
The problem I am facing is the fact that I need to make a keyboard where each key gives a different voltage to a analog input in the board.
I am bit confused..Your input will be keyboard i.e., keypad ?
You will produce output analog voltage for each different key?

Re: C-code analog input

Posted: Wed Dec 05, 2012 12:02 pm
by Dirk-Jan
It isnt the keypad from the e-block serie.
The project is supposed to be a little keyboard with keys that go from 0 till 9 and I am only allowed to use 1 analog input to recognize them.

So my idea was to put a voltage divider behind every key and that I would be able to read this value in the PIC board and translate it to a number.
With just flowcode code it is working great but now I have to rewrite it in c-code and get it to work the same.

Now the only part I am confused about is how to read a analog value in c-code.

Re: C-code analog input

Posted: Wed Dec 05, 2012 1:22 pm
by Enamul
Ok..I got the point. So which compiler you are going to use for c code.

Re: C-code analog input

Posted: Wed Dec 05, 2012 5:37 pm
by Benj
Hello,

For Flowcode v4 first of all compile your existing code to C using the analogue component and then use the View C menu option to look at the code.

The code should contain the ADC functions that get the analogue reading.

Copy the code out of here and paste it into a C icon and you should be about good to go.

Re: C-code analog input

Posted: Wed Dec 05, 2012 6:07 pm
by Enamul
Hello Ben

I was thinking about that easy solution..But I then thought he might not be using Boostc or HiTech C. May be some other compiler. Definitely the way you told is the best way to learn what I always do to understand. That's why whenever I try to produce anything new in C I try to find what Ben did here in C.

Re: C-code analog input

Posted: Thu Dec 06, 2012 4:24 pm
by Dirk-Jan
Okay I will take a look at that, but now I am wondering is it possible to do this because when I looked at the code before it seems like there are some functions and these functions are called upon in a main loop.
Is it actually possible to reproduce something like this?

Anyway I will have to take a look on it next monday because I don't have any school days till then.
Thanks for the replys and if I can't get it working I will talk with my teacher to chance the project and just leave it as it is!

Thanks!