{"id":7968,"date":"2012-10-16T23:05:23","date_gmt":"2012-10-17T03:05:23","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=7968"},"modified":"2012-10-16T23:05:23","modified_gmt":"2012-10-17T03:05:23","slug":"launchpad-msp430-pomodoro-timer-using-energia","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2012\/10\/16\/launchpad-msp430-pomodoro-timer-using-energia\/","title":{"rendered":"LaunchPad MSP430 pomodoro timer using Energia"},"content":{"rendered":"<p>I know a lot of people who bought the Texas Instruments <a href=\"http:\/\/www.ti.com\/tool\/msp-exp430g2\">MSP430 LaunchPad<\/a> development kit but never really got into it. I&#8217;m one of them; the $4.30 purchase price was compelling, but the requirement to install a huge proprietary IDE (with its own embedded C dialect) was just too much.<\/p>\n<p>For this reason, <a href=\"http:\/\/energia.nu\/\">Energia<\/a> is great. It&#8217;s a fork of the Wiring\/Arduino development environment for the MSP430. Looks just like Arduino, but quite red:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-7969\" title=\"Energia\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/10\/Screen-Shot-2012-10-16-at-22.39.06-.png\" alt=\"\" width=\"514\" height=\"642\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/10\/Screen-Shot-2012-10-16-at-22.39.06-.png 514w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/10\/Screen-Shot-2012-10-16-at-22.39.06--128x160.png 128w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/10\/Screen-Shot-2012-10-16-at-22.39.06--256x320.png 256w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/10\/Screen-Shot-2012-10-16-at-22.39.06--240x300.png 240w\" sizes=\"auto, (max-width: 514px) 100vw, 514px\" \/><\/p>\n<p>The basics of the language are the same, although the pin names and functions are different from the Arduino. The basic board also has a red and a green LED, a user button, and the obligatory reset button.<\/p>\n<p>Just to try out Energia, I wanted a useful project that only used the onboard hardware. I came up with a version of a pomodoro timer, similar to the one used in <a href=\"http:\/\/www.pomodorotechnique.com\/\">The Pomodoro Technique\u00c2\u00ae<\/a> time management method. The one I made has the following features:<\/p>\n<ul>\n<li>25 minute &#8220;green light&#8221; work period<\/li>\n<li>5 minute &#8220;red light&#8221; rest period<\/li>\n<li>At the end of the rest period, the green and red lights flash. You can choose to restart the timer (with the reset button), or turn the lights off with the user button.<\/li>\n<li>You can turn the timer off at any time with the user button, and restart it from zero with the reset button.<\/li>\n<\/ul>\n<p>For me, this electronic version has several advantages over the wind-up official timer:<\/p>\n<ul>\n<li>it doesn&#8217;t tick or ring distractingly<\/li>\n<li>it&#8217;s cheaper than the <a href=\"http:\/\/www.pomodorotechnique.com\/timer\/\">real thing<\/a><\/li>\n<li>it always resets to the same time.<\/li>\n<\/ul>\n<p>It does have a couple of possible disadvantages, though:<\/p>\n<ul>\n<li>it doesn&#8217;t give an indication of time left<\/li>\n<li>it&#8217;s not very accurate, since it uses the MSP430&#8217;s internal oscillator. Mine seems to give an approximately 26 minute work period, with a rest time that&#8217;s proportionally longer.<\/li>\n<\/ul>\n<p>Here&#8217;s the code (tested on a MSP-EXP430G2 board, version 1.4):<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/*\r\n\r\n launchpomodoro - simple task\/rest timer for TMS430\/Energia\r\n\r\n On reset: Green LED on for 25 minutes\r\n After 25 minutes: Red LED\r\n After 30 minutes: Flashing Red\/Green LED (until reset)\r\n On button press: all lights off.\r\n\r\n scruss - 2012-10-15\r\n\r\n *\/\r\n\r\n\/\/ 25 minutes\r\n#define ENDWORKTIME 1500000\r\n\/\/ 30 minutes\r\n#define ENDRESTTIME 1800000\r\n\r\nunsigned long start=0;\r\nint red=1; \/\/ for light flashing state at end of rest time\r\nint green=0;\r\n\r\nvoid setup() {\r\n  pinMode(GREEN_LED, OUTPUT);\r\n  pinMode(RED_LED, OUTPUT);\r\n  pinMode(PUSH2, INPUT);\r\n  digitalWrite(GREEN_LED, HIGH); \/\/ start work\r\n  digitalWrite(RED_LED, LOW); \/\/ stop rest\r\n  start=millis();\r\n}\r\n\r\nvoid loop () {\r\n  if ((millis()-start)&gt;ENDWORKTIME) {\r\n    digitalWrite(GREEN_LED, LOW); \/\/ stop work\r\n    digitalWrite(RED_LED, HIGH); \/\/ start rest\r\n  }\r\n\r\n  if ((millis()-start)&gt;ENDRESTTIME) {\r\n    flicker(); \/\/ warn that we've overrun\r\n  }\r\n\r\n  if (digitalRead(PUSH2) == LOW) { \/\/ push quiet\/off switch\r\n    off();\r\n  }\r\n}\r\n\r\nvoid flicker() { \/\/ toggle LEDs and wait a bit\r\n  red=1-red;\r\n  green=1-green;\r\n  digitalWrite(GREEN_LED, green);\r\n  digitalWrite(RED_LED, red);\r\n  delay(333);\r\n}\r\n\r\nvoid off() { \/\/ appear to be off\r\n  digitalWrite(GREEN_LED, LOW); \/\/ lights off\r\n  digitalWrite(RED_LED, LOW);\r\n  while (1) { \/\/ loop until reset\r\n    delay(50);\r\n  }\r\n}\r\n<\/pre>\n<p>(or if you&#8217;d rather have the archived sketch: <a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2012\/10\/launchpomodoro-121015a.zip\">launchpomodoro-121015a.zip<\/a>.)<\/p>\n<p>It would be trivial to port this to Arduino, but you would need some external LEDs, resistors and a pushbutton.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I know a lot of people who bought the Texas Instruments MSP430 LaunchPad development kit but never really got into it. I&#8217;m one of them; the $4.30 purchase price was compelling, but the requirement to install a huge proprietary IDE (with its own embedded C dialect) was just too much. For this reason, Energia is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[2207,2572,2570,2571,2573],"class_list":["post-7968","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-arduino","tag-energia","tag-msp430","tag-pomodoro","tag-timer"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-24w","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/7968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=7968"}],"version-history":[{"count":9,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/7968\/revisions"}],"predecessor-version":[{"id":7979,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/7968\/revisions\/7979"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=7968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=7968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=7968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}