Night Light AGoGo

No preview image

1 collaborator

Default-person Coram Bryant (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 4.1 • Viewed 330 times • Downloaded 18 times • Run 8 times
Download the 'Night Light AGoGo' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This model communicates with the sensors and output ports of a GoGo board. A GoGo board is an open source, easy-to-build, low cost, general purpose circuit board designed for educational projects.

This model helps you test your connection to your GoGo board, and serves as a starting point for building NetLogo activities that interact with the physical world.

HOW IT WORKS

The GoGo Extension for NetLogo provides primitives for communicating with a Gogo board

connected to your computer's serial port.

HOW TO USE IT

Connect a GoGo board to your computer's serial port. Then connect sensors, motors and lights to the board.

Press SETUP to begin communicating with the GoGo board. When prompted, enter the name of the serial port that's connected to your board.

Press PING to check if NetLogo is communicating with your GoGo board.

The sensor monitors -- SENSOR 1 through SENSOR 8 -- show the value of each of the sensors on the GoGo board.

The output port controls let you control the motors and lights connected to the output ports of your GoGo board.

A-ON turns the output port(s) on.

A-OFF turns the output port(s) off.

A-THISWAY/THATWAY control the direction of current to the output port(s). If a motor is connected to the output port, this determines the direction of motion.

A-REVERSE reverses the direction of current to the output port(s)

To change the amount of current going to the output port(s), set the A-POWER slider, then press the SET-A-POWER button.

The same applies to the other output ports B, C, and D.

To plot sensor values, set PLOT-SENSOR-1, PLOT-SENSOR-2, and PLOT-SENSOR-3 to the sensors you want to plot. Then press PLOT. At any time, you can clear the plot with the CLEAR-PLOT button. To stop plotting, press PLOT again. To export the data in your plot, right-click (on Macs, control-click) on the plot and choose "Export...".

THINGS TO TRY

Try connecting different sensors to the GoGo board. Temperature sensors, light sensors, pressure sensors.

Connect various motors, lights, and other circuits to the GoGo board's output-ports.

EXTENDING THE MODEL

Modify the plots procedure to plot more than three sensors.

NETLOGO FEATURES

This model uses the NetLogo GoGo Extension. For more information, see the GoGo Extension section of the NetLogo User Manual.

CREDITS AND REFERENCES

To learn about GoGo boards, see http://www.gogoboard.org.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

extensions [gogo]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
breed [night-lights night-light]
breed [sensors sensor]
breed [lights light]
night-lights-own [my-intensity]
lights-own [my-intensity]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
globals [
  serial-port   ;; different on different operating systems
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  
  if enable-gogo?
  [
  set serial-port user-one-of "Select a port:" gogo:ports
  gogo:open serial-port
  repeat 5
  [ if not gogo:ping
    [ user-message "The GoGo Board is not responding." ] ]
  gogo:talk-to-output-ports [ "a" "b" "c" "d" ]
  set-current-plot "Sensors"
  ]
  
  clear-all
  
  ifelse random-placement?
  [gen-night-lights]
  [gen-night-lights-test]
end 

to gen-night-lights
  create-night-lights num-night-lights
  [
    set shape "light"
    set size scale
    set color black
    setxy random-xcor random-ycor
  ]
end 

to gen-night-lights-test
  create-night-lights 1
  [
    set shape "light"
    set size scale
    set color black
    setxy light-radius 0
    set heading 0
  ]
  
  create-night-lights 1
  [
    set shape "light"
    set size scale
    set color black
    setxy (-1 * light-radius) 0
    set heading 90
  ]
  
  create-night-lights 1
  [
    set shape "light"
    set size scale
    set color black
    setxy 0 light-radius
    set heading 180
  ]
  
  create-sensors 1
  [
    set shape "light-sensor-only"
    set size scale
    setxy -.5 * light-radius -1 * light-radius
    set heading 0
  ]
  
  create-lights 1
  [
    set shape "light-bulb-only"
    set size scale
    setxy .5 * light-radius -1 * light-radius
    set heading 0
    set color black
  ]
end 

to go
  if (ticks mod 200 = 0)
  [
    clear-lights
    
    ifelse random-placement?
    [draw-lights]
    [show-night-lights-test]
    
    if not random-placement?
    [
      trip-virtual-sensor
    ]
  ]
  tick
end 

to show-night-lights-test
  
  ask night-light 0
  [
     set size scale
     setxy light-radius 0
  ]
  
  ask night-light 1
  [
     set size scale
     setxy (-1 * light-radius) 0
  ]
  
  ask night-light 2
  [
     set size scale
     setxy 0 light-radius
  ]
  
  ask sensor 3
  [
    set size scale
    setxy -.5 * light-radius -1 * light-radius
  ]
  
  ask light 4
  [
    set size scale
    setxy .5 * light-radius -1 * light-radius
  ]
  
  draw-lights
end 

to clear-lights
  ask patches [set pcolor black]
end 

to draw-lights
  ask night-lights
  [
    let sensation 0
    let my-sensor patch-right-and-ahead -18 -23
    if my-sensor != nobody
    [
      ask my-sensor
      [
        ;set pcolor yellow
        set sensation pcolor
      ]
    ]
    
    draw-light-versus-threshold sensation
   ]
  
  if enable-gogo?
  [
    ask lights
    [
      let sensation (500 - gogo:sensor 1) / 100
      if sensation < 0 [ set sensation 0 ]
      if sensation > 9.9 [ set sensation 9.9 ]
      
      write sensation
      write ""
      
      draw-light-versus-threshold sensation
    ]
  ]
end 

to draw-light-versus-threshold [sensation]
  ifelse sensation > threshold
    [set my-intensity 0]
    [set my-intensity (10 - sensation)]
    
    ;;set my-intensity (10 - sensation)
    
    print my-intensity
    
    draw-light
    ;;let sensor patch-right-and-ahead -18 -23
    ;;if sensor != nobody
    ;;[
      ;;print sensor
      ;;ask sensor
      ;;[
      ;;  set pcolor yellow
      ;;]
end 

to trip-virtual-sensor
 ask sensors
 [
    let sensation 0
    let my-sensor patch-right-and-ahead -25 -9
    
    ;;ask my-sensor [set pcolor yellow]
    if my-sensor != nobody
    [
      ask my-sensor
      [
        ;set pcolor yellow
        set sensation pcolor
        
       ;; print pcolor
      ]
    ]
    
    write sensation
    
    if enable-gogo?
    [
      ifelse sensation > threshold
      [ print "OFF" gogo:talk-to-output-ports [ "d" ] gogo:output-port-off ]
      [ print "ON" gogo:talk-to-output-ports [ "d" ] gogo:output-port-on]
    ]
  ]
end 

to draw-light
  ;; intensity is 0 - 9.9
  ;; radius = x*intensity
  ;; first x = intensity
  ;; next x = intensity - 1
  ;; next x = intensity - 2, etc.
  
  ;print self
  
  let intensity my-intensity
  ;print intensity
  
  ;; white is the brightest we can get
  if intensity > 9.9 [set intensity 9.9]
  
  ;; set the color of the light-bulb to the maximum intensity
  set color intensity
  let radius intensity
  set intensity 0
  let angle 310
  while [radius > 0]
  [
    ifelse radius < 1 [set angle 360] [set angle 310]
    ask patches in-cone (((3 * scale) / 10) * radius) angle
    [
      if intensity > pcolor
      [
        set pcolor intensity
      ]
      ;;set pcolor (pcolor + intensity / 2)
      ;;if pcolor > 9.9 [set pcolor 9.9]
    ]    
    set intensity (intensity + 1)
    set radius (radius - 1)
  ]
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; setup was here
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to gogo-ping
  carefully
  [ if not gogo:ping
    [ user-message "Unable to ping GoGo Board." ] ]
  [ user-message error-message ]
end 

to plot-sensor-value [ plot-sensor ]
 if plot-sensor != "none"
 [
   set-current-plot-pen plot-sensor
   if plot-sensor = "sensor 1"
       [ plot (gogo:sensor 1) ]
   if plot-sensor = "sensor 2"
       [ plot (gogo:sensor 2) ]
   if plot-sensor = "sensor 3"
       [ plot (gogo:sensor 3) ]
   if plot-sensor = "sensor 4"
       [ plot (gogo:sensor 4) ]
   if plot-sensor = "sensor 5"
       [ plot (gogo:sensor 5) ]
   if plot-sensor = "sensor 6"
       [ plot (gogo:sensor 6) ]
   if plot-sensor = "sensor 7"
       [ plot (gogo:sensor 7) ]
   if plot-sensor = "sensor 8"
       [ plot (gogo:sensor 8) ]
  ]
end 

to do-plot
  plot-sensor-value plot-sensor-1
  plot-sensor-value plot-sensor-2
  plot-sensor-value plot-sensor-3
  ;; to plot more sensors, add a line like this:
  ;; plot-sensor-value "sensor 5"
end 

; Copyright 2005 Uri Wilensky. This code may be freely copied, distributed,
; altered, or otherwise used by anyone for any legal purpose.

There is only one version of this model, created almost 14 years ago by Coram Bryant.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.