C-code analog input

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
Dirk-Jan
Posts: 8
Joined: Wed Oct 10, 2012 7:37 pm
Has thanked: 4 times
Contact:

C-code analog input

Post 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!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: C-code analog input

Post 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?
Enamul
University of Nottingham
enamul4mm@gmail.com

Dirk-Jan
Posts: 8
Joined: Wed Oct 10, 2012 7:37 pm
Has thanked: 4 times
Contact:

Re: C-code analog input

Post 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.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: C-code analog input

Post by Enamul »

Ok..I got the point. So which compiler you are going to use for c code.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: C-code analog input

Post 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.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: C-code analog input

Post 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.
Enamul
University of Nottingham
enamul4mm@gmail.com

Dirk-Jan
Posts: 8
Joined: Wed Oct 10, 2012 7:37 pm
Has thanked: 4 times
Contact:

Re: C-code analog input

Post 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!

Post Reply