Forum

analogRead?

More
#584 by ericleven
ericleven created the topic: analogRead?
Is there an analogous command in EZ Script to Arduino's analogRead ? Or are the pins on Foxonix all digital?

I'd like to trigger a sound based on the value of a photoresistor, but I can't figure a way to do that using Foxonix alone.

Please Log in or Create an account to join the conversation.

More
#586 by foxonix
foxonix replied the topic: analogRead?
Hi Eric:

The chip used in Foxonix does not have a built-in ADC (Analog-to-Digital Converter), so there is no command that is analogous to the analogRead function in the Arduino. If you're already using an Arduino, the easiest thing might be to use the Arduino to read the sensor, and then have the Arduino put out a digital code to the Foxonix board. Your Foxonix program can read the port and then act accordingly. We've actually done this for an internal project where we used an Arduino to read a temperature sensor and used Foxonix to say what the temperature is.

By reading one port you can decode up to 16 different values. By reading two ports you can decode up to 256 different values, though it requires some extra steps. I have attached a sample program for you that illustrates how to do this. (This is not an "official" example, but we put it together a while back for a user that wanted to do something similar.)

The command for reading a port can be found in the reference section: Mi=Pn . You might also find this forum post helpful.

Foxonix - make your ideas heard.
@foxonixdev
Attachments:

Please Log in or Create an account to join the conversation.

More
#588 by ericleven
ericleven replied the topic: analogRead?
Thanks for the info; I think I'm running up against my own "maker" vs "actual engineer" limitations (registers are sort of like variables? Ports are kind of like pins?).

Any chance you could post that temperature sensor code? I'm curious to see how you actually send the value of a variable in Arduino to a port on Foxonix. No rush, just curious.

Thanks,

-eric

Please Log in or Create an account to join the conversation.

More
#589 by foxonix
foxonix replied the topic: analogRead?
That's OK. We want to make this easily understandable so that it works for all makers. A register is a small piece of memory inside the chip where you can store data. The Atmel chip used on the Arduino has these registers, too, but they're not explicitly called registers in the Arduino code. Instead you just define a variable and the compiler takes care of the rest. In Foxonix, you don't name your variables, you refer to them by register name, like M0, M1, and so on.

A port is just a set of pins. On Atmel chips like the one you might find in an Arduino, the ports are called Port A, Port B, Port C, etc. Arduino maps these to pin numbers like 0, 1, 2, 3, 4, and so on. With Foxonix, the ports are called P1, P2, P3, and P6. If you're referring to a specific pin, you might say P1.2 which is Port1, pin 2. Nothing to get hung up about, really - just nomenclature.

The thermometer code might need a little clean-up, but we'll look into posting that for you.

Foxonix - make your ideas heard.
@foxonixdev

Please Log in or Create an account to join the conversation.

Time to create page: 0.020 seconds