# Y variable known when x variable known

**URL:** <https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412>\
**Category:** Programming\
**Created:** [August 26, 2024, 11:47am UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412 "2024-08-26T11:47:09Z")\
**Posts on this page:** 9\
**Page:** 5

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 3, 2024, 6:03am UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/81 "2024-09-03T06:03:21Z")

</div>

> [@petercl14](#):
>
> never seen this code before useXnY(); and readXnY

Does your sketch not call any functions such as pinMode(), Serial.print(). digitalRead(), digitalWrite() etc, etc ? They are built in functions

You can write your own functions, such as useXnY() and call those as illustrated by @DaveX and I

As to the source of the code, do you mean the syntax of how to call a function ? That is standard C/C++ functionality so do not expect it to be in the Arduino Reference which concentrates on Arduino specific topics

I have to say that the more this thread goes on I am more suspicious of your reluctance to provide information, post your code and your apparently naïve questions.

---

<div class="post-metadata">

**Author:** ![petercl14](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/petercl14/32/1013044_2.png) [@petercl14](https://forum.arduino.cc/u/petercl14)\
**Post date:** [September 3, 2024, 6:07am UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/82 "2024-09-03T06:07:50Z")

</div>

It was just a thought. You are right of course. “you want to do something specific with y when x is a certain value, and what you do with y changes based on the value of x.”

The coding ‘useXnY’ and ‘readXnY’ looks like the answer. I need to know more about this code before I can use it properly. Do you know where I can find this code? Examples of its use, like they give for coding in Arduino help, would be very useful.

---

<div class="post-metadata">

**Author:** ![petercl14](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/petercl14/32/1013044_2.png) [@petercl14](https://forum.arduino.cc/u/petercl14)\
**Post date:** [September 3, 2024, 6:40am UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/83 "2024-09-03T06:40:03Z")

</div>

I believe you are right now. Probably it looked too easy so that I started to look for something more complicated.  
on one line in the sketch the value of x is derived from an equation. on the next line the value of y is derived from a different equation. their values are derived at the same time as shown by a real time clock. so every time there is an x value there will be a corresponding y value. they are linked together permanently. when one action is done with the x value, at the same time an action will be done with the y value. the x value moves a servo motor. the y value moves a different servo motor. a robotics application.  
I have been asked to give the equations. They would be meaningless to the forum unless i explained what they were for and also how they were derived. This topic would then go on for the next 6 months and nobody wants that.

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [September 3, 2024, 11:24am UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/84 "2024-09-03T11:24:39Z")

</div>

> [@racpi](#):
>
> Any bets on object tracking with pixycam?

I doubt it. @petercl14 obviously doesn't have the requisite coding skill. And, even if he's copying / modifying and existing code, it's hopeless.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [September 3, 2024, 12:18pm UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/85 "2024-09-03T12:18:41Z")

</div>

> [@petercl14](#):
>
> go on for the next 6 months

Best stone soup ever!

---

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [September 3, 2024, 1:00pm UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/86 "2024-09-03T13:00:40Z")

</div>

> [@petercl14](#):
>
> when one action is done with the x value, at the same time an action will be done with the y value. the x value moves a servo motor. the y value moves a different servo motor. a robotics application.

So x and y are servo angles? Then useXnY() could be:

```arduino
void useXnY(){
  ServoX.write(x);
  ServoY.write(y);
}

```

Done!

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [September 3, 2024, 1:20pm UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/87 "2024-09-03T13:20:10Z")

</div>

> [@petercl14](#):
>
> The coding ‘useXnY’ and ‘readXnY’ looks like the answer. I need to know more about this code before I can use it properly. Do you know where I can find this code?

I saw this looking back. _useXnY_ and _readXnY_ are just function names that @DaveX made up to illustrate how code might be written to use or receive two values passed to it.

In the code where you see those two functions they are serving as stubs.

> A stub is a function that has the expected signature (i.e. name and accepted arguments), but an incomplete implementation

waiting and ready for you to pour your heart into what to actually do to use, or read, x and y.

a7

---

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [September 3, 2024, 1:26pm UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/88 "2024-09-03T13:26:02Z")

</div>

Exactly.

> [@Planning and Implementing an Arduino Program](https://forum.arduino.cc/t/planning-and-implementing-an-arduino-program/252364/3):
>
> Before we go any further let's try to describe all the "actions" that must happen for this project to work. For the moment don't worry about the order of things - just jot them down as they occur to you. For example ...
> 
> flash LEDa  
> flash LEDb  
> check the buttons  
> set the flashing period  
> ask the user for input  
> get the user's response  
> move the servo  
> read the potentiometer  
> set the servo position
> 
> Without noticing it we now have a huge part of the program designed. Let's make a separate function for each of those actions.
> 
> ```arduino
> void flashLedA() {
> 
> }
> 
> void flashLedB() {
> 
> }
> 
> void checkButtons() {
> 
> }
> 
> void setFlashPeriod() {
> 
> }
> 
> void askForUserInput() {
> 
> }
> 
> void getUserResponse() {
> 
> }
> 
> void moveServo() {
> 
> }
> 
> void readPotentiometer() {
> 
> }
> 
> void setServoPosition() {
> 
> }
> 
> ```
> 
> Of course at this stage none of these functions can do anything as they have no code within them - but we'll worry about that later.
> 
> Now, how would you go about using all those little functions? Let's try something very simple. What about this ...
> 
> ```arduino
> void setup() {
> 
> }
> 
> void loop() {
> flashLedA();
> flashLedB();
> checkButtons();
> setFlashPeriod();
> askForUserInput();
> getUserResponse();
> moveServo();
> readPotentiometer();
> setServoPosition();
> }
> 
> ```
> 
> Together with the earlier functions this is a complete Arduino sketch that will compile and run - even if it does nothing.
> 
> ...

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 2, 2025, 1:26pm UTC](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412/89 "2025-03-02T13:26:53Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.arduino.cc/t/y-variable-known-when-x-variable-known/1295412.md?page=4)
