Log In  

Not sure exactly how to phrase this intelligently so...

How do I use the GPIO ports to send and receive data in the web player?

I managed to get a cart together that will send out a score to an endpoint so I can do stuff with it, which is awesome. I used this P8 snippet and it works great.

But I don't really understand what's happening or why...in both the JS and the Pico-8 code. I see a bunch of poke() commands and 256 math stuff but just don't know what they're doing. The P8 manual is pretty light on the GPIO stuff so I'm not sure where else to turn.

I saw someone on Twitter with a demo of a web player cart reading tweets, and that got me thinking about other things I could do with P8 carts if I had the ability to pull down data.

I'm not really looking to make a 2-player network game or anything...just wanting to pass data back and fourth.

P#25702 2016-07-21 23:11 ( Edited 2016-07-23 01:02)

For the PICO-8 code, you're poking into the gpio ports mentioned in the forums. For the JS code, it's similar to the pico8_buttons variable. You define a pico8_gpio variable near where you setup the module, then you pull from that every once in a while. However, there's no way to have the JS synced with the player, AFAIK.

In other words, you'd have to use setTimeout and risk the chance of reading the same data multiple times per second. The only way I can see to change this is to have the PICO-8 code set a certain port to 1, then have the JS occasionally check that port. If the port is 1, it checks the rest of the ports, does things, and sets that port back to 0. The PICO-8 code would then wait for the port to go back to 0.

Maybe there should be another variable the JavaScript can define, being pico8_update. Every frame, after updating, PICO-8 will check for that JavaScript variable. If it exists and is a function, it'll run the function.

P#25755 2016-07-22 20:54 ( Edited 2016-07-23 00:54)

I think a lot of my GPIO questions and answers like in the Twitter client over here: https://www.lexaloffle.com/bbs/?tid=3909

Gonna peruse that code and see what I can figure out, I think it holds the key.

P#25757 2016-07-22 21:02 ( Edited 2016-07-23 01:02)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 12:02:26 | 0.007s | Q:12