send_random_floats/send_random_floats.rs
1use rand::Rng;
2use std::thread;
3use std::time::Duration;
4
5///! An example to send random floats via FUDI over UDP
6///! to a pure data patch every second.
7extern crate fudi_rs; // add crate to talk to pure data
8
9fn main() {
10 println!("press CTRL + C to stop"); // print helpful hint
11
12 // create new netsend with 127.0.0.1:39942 as destination for messages
13 let netsend = fudi_rs::NetSendUdp::new("127.0.0.1:39942");
14
15 // forever do ...
16 loop {
17 let f = rand::thread_rng().gen_range(-139.8..694.5); // generate random number between -139.8 and 694.5
18 let msg = fudi_rs::PdMessage::Float(f); // create a float message
19 println!("sending {:?}", msg);
20 netsend.send(&msg).expect("sending message failed"); // actually send the float message
21 thread::sleep(Duration::from_secs(1)); // sleep for 1 second
22 }
23}