basic/
basic.rs

1
2use st3215::ST3215;
3
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    // Créer une instance ST3215 connectée au port COM3
6    let servo = ST3215::new("COM3")?;
7
8    // Lister tous les servos disponibles
9    let ids = servo.list_servos();
10    println!("Servos trouvés: {:?}", ids);
11
12    // Pour chaque servo trouvé
13    for id in ids {
14        println!("\n=== Servo {} ===", id);
15        
16        // Lire et afficher les informations du servo
17        if let Some(position) = servo.read_position(id) {
18            println!("Position actuelle: {}", position);
19        }
20        
21        if let Some(voltage) = servo.read_voltage(id) {
22            println!("Tension: {:.1} V", voltage);
23        }
24        
25        if let Some(temp) = servo.read_temperature(id) {
26            println!("Température: {} °C", temp);
27        }
28        
29        if let Some(current) = servo.read_current(id) {
30            println!("Courant: {:.1} mA", current);
31        }
32
33        // Déplacer le servo vers la position
34        let deg: u16 = 65;
35        let pos: u16 = deg * (4096.0 / 360.0) as u16;
36
37        println!("Déplacement vers la position {}...", deg);
38
39        servo.move_to(id, pos, 2400, 50, true);
40        
41        println!("Mouvement terminé!");
42    }
43
44    Ok(())
45}