Archive | February 2016

Teaching event-based programming – a traffic light

Recently as I was looking through my blogroll, I read Mark Guzdial’s review of the K12CS.org Framework. I wished I had been able to review the framework with a group – I didn’t feel that I generated great ideas about it on my own, but I did like reading Mark’s. Reading my social media feed sometimes impacts what I’m going to teach. In this case, Mark made a point about models of computing:

Great research by people like John Pane at CMU has shown that novices think of programs as responding to events, being reactive (e.g., think apps, games, GUI interfaces). Thinking of computing as input-processing-output is an older model, difficult to understand, and less common today.

 

Huh. I had been teaching programming as input –> do stuff –> output and wondering to myself what to do when this model broke down. I never really thought about how I teach event-based programming differently. I decided I would give it a try, though. In my 7th-8th grade CS class, my kids had learned about variables, conditionals, and functions. Normally I would plow right into iteration but I decided to take a detour and do some activities with the kids on event-based programming. We did a couple of examples working in Processing with draw() and mouseClicked() and keyPressed(). I decided to introduce an activity involving a state machine to teach the difference between linear programming and event-based programming.

I talked with the kids about how many of us think a traffic light works. We see it as a linear set of steps.

trafficlight_maya

trafficlight1

But in reality, we know the traffic light has a set of sensors. And when a sensor is tripped and other conditions are met, then the traffic light advances to the next state. You can model the state with a variable. In this case, I used “lc” for light color. We can model the sensors with button clicks and key presses.

trafficlight2

We wrote this program together, imagining that the mouse click simulates a timer expiring, and the space bar simulates the sensor that detects your car. I did this as a teacher-led launch. Kids followed along and ran their programs. Easy.

http://www.openprocessing.org/sketch/311664

 

The kids asked about how you simulate a real timer. In Processing, there isn’t an easy implementation of a “delay” function, so you have to poll for a timer. There is a built-in function millis() that returns the number of milliseconds since the program had started. The kids played with the millis() function and had fun writing the time to the screen. So for the next class, I decided a program that used timers would be a good extension and problem-solving activity.

In the second class, we looked at this state machine model.

trafficlight3

My amateurish drawing shows looping arrows where you are polling the timer. As long as the “ready” variable, for example, is 0, then the light stays the same. As soon as the “ready” variable changes to 1, then you can advance to the next state. You can check for “ready” by doing some math on variables that store the value of millis(). One variable stores millis() over and over again. Another variable only stores millis() when the state has just changed.

I put the kids with a partner and made this a pair programming assignment.  We reviewed the norms of pair programming. I gave them a starter program that just showed a red screen and used the millis() function to display the elapsed time. I had some variables in the program but did not tell the kids how to use them. Their task was: turn the program into a timed traffic light. It should turn the red light on for a certain time, then the green light for a longer time, then the yellow light for a very short time, and then go back to red.

This is the starter program.

// 0 is red, 1 is yellow, 2 is green 
int lc = 0; 
int ready = 0; 
int oldms; 
int newms; 
int elapsedms; 
int interval; 

void setup() 
{   
  size(400,400); 
  ready = 0; 
  oldms = millis();
  newms = millis(); 
  elapsedms = newms - oldms; 
  interval = 5000; 
}
void draw() 
{
  if(lc == 0) 
  { 
    background(255,0,0); 
  } 
  else if(lc == 1) 
  { 
    background(255,255,0); 
  } 
  else if(lc == 2) 
  { 
    background(0,255,0); 
  } 
  newms = millis(); 
  elapsedms = newms - oldms; 
  textSize(30); 
  fill(0,0,0); 
  text(elapsedms, 150,150); 
} 



The kids split into pairs and started working. After a while, a few groups were close – they could check for a certain elapsed time and then change the light’s state variable so it switched colors. They didn’t know how to reset the timer, so after about 20-30 minutes, most of the kids could change red-green-yellow and then didn’t know how to get back to red.

So I did a catch-and-release where we talked about the polling loop.  I showed boxes that represented the values of “oldms”, “newms”, and “elapsedms” each time through the draw() function. Some kids figured out on their own that the way to reset the timer is by assigning “oldms” to millis() when you change the light’s color. Others figured out different solutions  and it was interesting to see what they came up with.

The activity took most kids until the end of the class. On the third class, I asked all of the pairs to copy and paste their programs into OneNote. I then called up several groups to do a walkthrough of their solution. They did a really good job presenting. I like OneNote for this kind of sharing because the rest of the class could copy the code and run it to understand what the presenting group did.

Here are some of the solutions! I liked how each group approached it a little differently. Some used my variables and some made up their own. Some used nested “if” statements and some used complicated boolean expressions. Some reset the timer after each state change and some waited until after a complete cycle of the traffic light.

Luke and Andrew’s Method

Anna and Kay’s method

Ryan and Parker’s method

I enjoy seeing the students have their lightbulb moments, and it’s also fun to have the overachieving students that can’t resist being a little creative with their programs.

Maya’s Traffic Light

Ben and Anthony’s Traffic Light with car (it stops on red, goes on green, and speeds up on yellow)

I liked this workshop model with the teacher-led launch, the worktime in pairs, and then the student-presented summary. I think it was a good problem-solving activity for the kids, and for me it was a nice departure from the input-stuff-output model of programming.

 

 

 

National Summit on Teacher Leadership #2016NSTL

I had the privilege of attending the National Summit on Teacher Leadership in Washington, DC over the weekend of February 5-6. This summit involved the Department of Education, the Council of Chief State School Officers, the National Education Association, and the American Federation of Teachers. It was an awesome accomplishment in itself to get representatives from the four groups in the room at the same time. The purpose of a summit is to generate ideas. I was selected to be a teacher-leader representative from the NEA and had three peers from each of the other three organizations: Jeff representing the CCSSO, Kiragu representing the AFT, Karuna representing the Department of Education. Here we are with Dr. Andy Hargreaves, a researcher in leadership and teacher leadership programs. He’s the author of the book Uplifting Leadership.

Jeff, Kiragu, Dr. Hargreaves, Karuna, and me.

Jeff, Kiragu, Dr. Hargreaves, Karuna, and me.

Teams from over 20 states, plus the Department of Defense school system, attended the summit. We sat at a large table and brainstormed around questions having to do with leadership and the teaching profession. Each of the teacher-leaders moderated a session. Each session had a central question. My job, and the job of the other teacher-leaders, was to help guide the discussion, keep it on topic and on time, allow everyone a voice, and keep the discussion solution-focused.

The leaders of the four partner organizations were present and participated in the discussions. It was exciting and so important to hear all of our leadership on the same page. I also got a small collection of celebrity photos. I missed getting a picture with Chris Minnich who was there also.

The discussion started slowly and conservatively at first. We later became more passionate, sometimes emotional, sometimes solution-focused, sometimes preachy. We touched on many different themes around teacher-leadership and I felt we covered an awful lot of ground.

I would like to share a few stories from the summit.

One of my fellow moderators is an incredible and dedicated teacher from West Baltimore. His students can’t drink the water in their school building. They don’t have heat consistently. Computers, robots, musical theater, speech and debate, and science bowl teams are laughably inaccessible. Remember the riots in Baltimore last year? Teenagers smashed a police car. Students from a school with no drinkable water, no heat, no certified math teacher, 50% turnover of teachers every year, poor access to computers and modern learning tools. The national guard was sent in to deal with the rioters. Imagine knowing the government has the money to send in the military to deal with your students… but somehow, no money for drinkable water.

One participant gets her students involved in community service projects, engaging the community in dialogue about race and equity, looking for ways to help their neighbors. She knows well that her students won’t make the top test scores. She hopes to have them measured by different success measures. If your kids are engaged in real-life projects, searching for problems in their community and actively solving them and communicating about it – if they are kind to each other and productive and informed – have you done a good job?

Another participant helped me understand the world of professional development a little better. As she talked about the best professional development she ever had – in her case, it involved a book study, a conference, an EdCamp, and then a presentation she designed and presented to fellow teacher-learners – I realized that the path to teacher leadership can’t involve canned professional development or standardized metrics. You will realize the potential of leadership if your learning is personalized, designed by you, and where the success metrics are matched to your goals. I wonder how we achieve this for everyone in our profession.

I made a little slide show about the major themes from the weekend. If you look at the whole picture, I think an action plan starts to become clear. But it has to match your needs and your students’ needs. What will you do at your school?

https://docs.google.com/presentation/d/1csATfbqhHPRm7dYa49jvJeOKL0p3sMv3PsprLE0E4Jc/edit#slide=id.p

National Summit on Teacher Leadership