1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # 運動用簡易計時 2021-12-06 by 離 in R library(beepr) timer <- function(onsec,offsec,min) { sum <- round(min*60/(onsec+offsec)) print(paste(onsec,"sec. on,",offsec,"sec. off, total:",sum ,"reps,", min, "mins")) count <- 0 Sys.sleep(10) print(paste("start at:",Sys.time())) beep("coin") repeat { count = count+1 Sys.sleep(onsec) beep("ping") Sys.sleep(offsec) beep("coin") print(count) if(count == sum) { beep("fanfare") print(paste("end at:",Sys.time())) break } } } timer(onsec = 60, offsec = 15, min = 30) # e.g. [1] "60 sec. on, 15 sec. off, total: 24 reps, 30 mins" |
Direct link: https://paste.plurk.com/show/q2mbiswKCbC0RHlHqxyR