Skip to content

Commit

Permalink
Fixing the example for the photocell sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
Guney Saramali committed Aug 2, 2024
1 parent 8c39d51 commit e5a8404
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/flow_sensor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func main() {
defer line.Close()
defer lfs.CloseChannels()

// listen the measurement if you want to take action or print the values. Do whatever you want.
// Listen the measurement if you want to take action or print the values. Do whatever you want.
// Here shutdown when 100 liters are measured
for {
printMeasurement(<-lfs.Subscribe())
if lfs.GetMeasurement() > 100 {
Expand Down
14 changes: 6 additions & 8 deletions examples/photocell_sensor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@ func main() {
defer line.Close()
defer pcs.CloseChannels()

// listen the measurement if you want to take action or print the values. Do whatever you want.
for {
printMeasurement(<-pcs.Subscribe())
if pcs.GetMeasurement() > 100 {
break
}
// Listen the measurement if you want to take action or print the values. Do whatever you want.
// Here shutdown after measuring 1000 times
for i := 0; i < 1000; i++ {
printMeasurement(i, <-pcs.Subscribe())
}

}

func printMeasurement(measurement int) {
log.Printf("Brightness is: %d", measurement)
func printMeasurement(noOfMeasurement int, measurement int) {
log.Printf("Measurement %d, Brightness is: %d", noOfMeasurement, measurement)
}

0 comments on commit e5a8404

Please sign in to comment.