Giter Site home page Giter Site logo

Comments (6)

fjesbok64 avatar fjesbok64 commented on July 27, 2024
from guizero import *

arduinoData=[]
for i in range (1,25):
arduinoData.append(i*2)
print("Array: ",arduinoData) #Works OK

def read_sensor():
for i in range (0,24):
return arduinoData[i] # PRINTS ONLY FIRST LOOPING
#exchanged from original: return random.randrange(3200, 5310, 10) / 100

def update_label():
text.value = read_sensor()

recursive call
text.after(1000, update_label)

if name == 'main':
app = App(title='Sensor Display!',
height=200,
width=600,
layout='grid')

title = Text(app, 'Sensor value:', grid=[1, 1], size="50", color="blue")
text = Text(app, "xx", grid=[2, 1], size="50", color="red")

text.after(1000, update_label)
app.display()

from guizero.

martinohanlon avatar martinohanlon commented on July 27, 2024

The code is missing its indentation, could you update please.

I have edited the issues to format the code so its easier to read.

It isnt obvious to me what the program is trying to do.

Re this function:

def read_sensor():
    for i in range (0,24):
        return arduinoData[i] # PRINTS ONLY FIRST LOOPING

Regardless of how this function is called (via update, repeat, or call directly) it is only ever going to return the first value in the list. The for loop will start from 0 each time it is run.

This is not an issue with guizero so adding help wanted label.

from guizero.

fjesbok64 avatar fjesbok64 commented on July 27, 2024

I see the counter i in def read_sensor() loop will be reset for every call.
So counter has to be outside the loop and then i could not make it work. Where in code should the retreaving of values from the arduinoData() be placed to increment ?

from guizero.

bsimmo avatar bsimmo commented on July 27, 2024

Feel free to pop to https://forums.raspberrypi.com/viewforum.php?f=32 especially if you are then going to interface and Arduino physically.

Although actually displaying code on the RPi forum is not as good as here.

Simple method.
Create a global counter variable for i
Increment that either in update_ or read_ as you see best
Reset when it reaches its limit after the read_

from guizero.

fjesbok64 avatar fjesbok64 commented on July 27, 2024

Thanks bsimmo. I will try that. 👍

from guizero.

martinohanlon avatar martinohanlon commented on July 27, 2024

Closing due to inactivity.

from guizero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.