Difference between revisions of "What is variable?"

From Interaction Station Wiki
Jump to navigation Jump to search
(Created page with " =Variables= In programming, a variable is a value that can change, depending on conditions or on information passed to the program.")
 
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
  
 
In programming, a variable is a value that can change, depending on conditions or on information passed to the program.
 
In programming, a variable is a value that can change, depending on conditions or on information passed to the program.
 +
 +
[[File:Images.jpeg]]
 +
 +
for example, if we want to read the values of light sensors from the CPX,
 +
 +
we need to give it a name so we can call out the values in our code when we need it.
 +
 +
in this case, we can call it sensorvalue we can also call it x or y or i.
 +
 +
for example:
 +
<syntaxhighlight lang="Python">
 +
import time
 +
from adafruit_circuitplayground import cp
 +
 +
 +
while True:
 +
    sensorValue=cp.light
 +
    print(sensorValue)
 +
    cp.play_tone(sensorValue,0.2)
 +
    time.sleep(0.5)
 +
 +
</syntaxhighlight>
 +
 +
in this case, sensorValue is a variable, its value will be updated ever time the code runs

Latest revision as of 15:39, 3 September 2024

Variables

In programming, a variable is a value that can change, depending on conditions or on information passed to the program.

Images.jpeg

for example, if we want to read the values of light sensors from the CPX,

we need to give it a name so we can call out the values in our code when we need it.

in this case, we can call it sensorvalue we can also call it x or y or i.

for example:

import time
from adafruit_circuitplayground import cp


while True:
    sensorValue=cp.light
    print(sensorValue)
    cp.play_tone(sensorValue,0.2)
    time.sleep(0.5)

in this case, sensorValue is a variable, its value will be updated ever time the code runs