Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- // Importations
- import (
- "fmt"
- "time"
- )
- // Constantes
- var DOpened = 0
- var DClosed = 1
- var DOpening = 2
- var DClosing = 3
- var DOpeningStopped = 4
- var DClosingStopped = 5
- // Variable d'état
- var state = DClosed
- // État au format chaine
- func stateToString(state int) string {
- switch state {
- case DOpened:
- return "Ouvert"
- case DClosed:
- return "Fermé"
- case DOpening:
- return "En cours d'ouverture"
- case DClosing:
- return "En cours de fermeture"
- case DOpeningStopped:
- return "Ouverture arrêtée"
- case DClosingStopped:
- return "Fermeture arrêtée"
- default:
- return "État inconnu"
- }
- }
- // Afficher l'état au format chaine
- func displayState(state int) {
- fmt.Printf("État : %s\n", stateToString(state))
- }
- // Appuyer sur le bouton
- func pushButton(state *int) {
- fmt.Printf("Appui sur le bouton\n")
- switch *state {
- case DOpened, DOpeningStopped:
- *state = DClosing
- displayState(*state)
- for i := 0 ; i < 5000 ; i++ {
- if *state == DClosing {
- time.Sleep(1 * time.Millisecond)
- } else {
- return
- }
- }
- *state = DClosed
- displayState(*state)
- case DClosed, DClosingStopped:
- *state = DOpening
- displayState(*state)
- for i := 0 ; i < 5000 ; i++ {
- if *state == DOpening {
- time.Sleep(1 * time.Millisecond)
- } else {
- return
- }
- }
- *state = DOpened
- displayState(*state)
- case DOpening:
- *state = DOpeningStopped
- displayState(*state)
- case DClosing:
- *state = DClosingStopped
- displayState(*state)
- }
- }
- func main() {
- var input string
- for {
- fmt.Scanln(&input)
- go pushButton(&state)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement