{"id":101,"date":"2019-04-15T10:30:37","date_gmt":"2019-04-15T16:30:37","guid":{"rendered":"http:\/\/www.wolfpack.xyz\/blog\/?p=101"},"modified":"2019-04-23T02:04:34","modified_gmt":"2019-04-23T08:04:34","slug":"objects-in-space-panel-meter-tutorial","status":"publish","type":"post","link":"http:\/\/www.wolfpack.xyz\/blog\/?p=101","title":{"rendered":"Objects in Space Panel Meter Tutorial"},"content":{"rendered":"\n<div class=\"wp-block-media-text alignwide has-media-on-the-right\" style=\"grid-template-columns:auto 43%\"><figure class=\"wp-block-media-text__media\"><img decoding=\"async\" loading=\"lazy\" width=\"634\" height=\"322\" src=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/MkII-Meters.jpg?resize=634%2C322\" alt=\"\" class=\"wp-image-102\" srcset=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/MkII-Meters.jpg?resize=1024%2C520 1024w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/MkII-Meters.jpg?resize=300%2C152 300w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/MkII-Meters.jpg?resize=768%2C390 768w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/MkII-Meters.jpg?resize=816%2C415 816w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/MkII-Meters.jpg?w=1189 1189w\" sizes=\"(max-width: 634px) 100vw, 634px\" data-recalc-dims=\"1\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>\n\nI have cleaned up my code from my previous post and want to make it available for anyone to try out themselves.  <br>This code drives two 5v volt meters much like the developers have in their MkII console.   \n\n<\/p>\n<\/div><\/div>\n\n\n\n<p style=\"background-color:#9b1616\" class=\"has-text-color has-background has-very-light-gray-color\"><em>Remember to set &#8220;hardware=true&#8221; in your game&#8217;s config file or else it wont work!<\/em><\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"634\" height=\"357\" src=\"https:\/\/www.youtube.com\/embed\/Oe7CYhRSPyM?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation\"><\/iframe><\/span>\n<\/div><figcaption>Running the code below!<\/figcaption><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/* Objects in Space Panel Meters\n   This example displays telemetry from the game on an LCD and 5v panel meters. \n   It uses the built-in LiquidCrystal library - see\n   https:\/\/www.arduino.cc\/en\/Reference\/LiquidCrystal for details.\n\n   DISPLAYS POWER FLOW AND TOTAL POWER AS A PWM ON THE LCD SCREEN AND\n   PASSES IT TO PWM PINS 9 AND 10 FOR USE ON 5V PANEL METERS.\n\n   The LCD is only used to display data for debuging purposes and can be\n   omitted without affecting the meters.\n   \n   CODE BY DAK47922 - http:\/\/www.wolfpack.xyz\/blog\n   ----------------\n*\/\n#include &lt;LiquidCrystal.h&gt;\n#include &lt;ArduinosInSpace.h&gt;\nint flow; \/\/Declare our variables as integers\nint power;\n\n\/\/ Initialise the LiquidCrystal library\nLiquidCrystal lcd(12, 11, 5, 4, 3, 2);\n\n\/\/ Create an ObjectsInSpace object. The first parameter is the\n\/\/ serial interface to use. The second is the number of values\n\/\/ we&#039;re requesting from the game.\nObjectsInSpace OIS(Serial, 2);\n\nvoid setup() \n{\n  pinMode(9, OUTPUT); \/\/ POWER FLOW PWM TO METER\n  pinMode(10, OUTPUT); \/\/ BATTERY PWM TO METER\n  \n  \/\/ set up the LCD&#039;s number of columns and rows:\n  \/\/ specific for a 16x2 LCD screen (change this for different sizes)\n  lcd.begin(16, 2);\n\n  Serial.begin(9600); \/\/must be 9600\n  OIS.begin(); \/\/begin the handshake\/synchronisation with the game\n\n  \/\/ register the command to get the power flow from the game.  (a value between -100 and 100)\n  OIS.registerInt(POWER_FLOW_PERCENT, powerflowCallback);\n  \/\/ register the command to get the total power from the game. (a value between 0 and 100)\n  OIS.registerInt(POWER_LEVEL_PERCENT, powerlevelCallback);\n\n  OIS.activate(); \/\/stop syncing and ACTIVATE\n}\n\nvoid loop() \n{\n  OIS.update(); \/\/required to keep getting info from the game.\n}\n\n\/\/ because we registered this in setup(), this gets called every time\n\/\/ OIS.update() is called. therefore our info is refreshed\nvoid powerflowCallback(int channel, int data)\n{\n  flow = map(data, -100, 100, 0, 255);    \/\/ Converts our -100 to 100 value to a useable PWM value (0 to 255)\n  lcd.setCursor(0,0);                     \/\/ Set the cursor to the top left of the screen (0,0)\n  lcd.print(&quot;FLOW PWM:   &quot;);              \/\/ Prints our label on the screen plus 3 empty spaces to insure our value which can be 1, 2, or 3 digits is properly cleared and reprinted\n  lcd.setCursor(9,0);                     \/\/ Backs up 3 spaces to print our data value on the empty spaces from the previous line\n  lcd.print(flow);                        \/\/ prints our PWM value\n  analogWrite(9, flow);                   \/\/ Writes our PWM value to pin 9\n}\n\n\nvoid powerlevelCallback(int channel, int data)\n{\n  power = map(data, 0, 100, 0, 255);      \/\/ Converts our 0 to 100 value to a useable PWM value (0 to 255)\n  lcd.setCursor(0, 1);                   \/\/set the cursor to the 1st position of the second row\n  lcd.print(&quot;BATT PWM:   &quot;);             \/\/ Prints our label plus 3 empty spaces like above\n  lcd.setCursor(9,1);                    \/\/ Backs up 3 spaces to print our data value on the empty spaces from the previous line\n  lcd.print(power);                      \/\/ prints our PWM value\n  analogWrite(10, power);                \/\/ Writes our PWM value to pin 10\n}\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"634\" height=\"466\" src=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/OiSMeter.png?resize=634%2C466\" alt=\"\" class=\"wp-image-104\" srcset=\"https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/OiSMeter.png?resize=1024%2C753 1024w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/OiSMeter.png?resize=300%2C221 300w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/OiSMeter.png?resize=768%2C565 768w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/OiSMeter.png?resize=816%2C600 816w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/OiSMeter.png?w=1268 1268w, https:\/\/i0.wp.com\/www.wolfpack.xyz\/blog\/wp-content\/uploads\/2019\/04\/OiSMeter.png?w=1902 1902w\" sizes=\"(max-width: 634px) 100vw, 634px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p><\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-101\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.wolfpack.xyz\/blog\/?p=101&amp;share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-101\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.wolfpack.xyz\/blog\/?p=101&amp;share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>I have cleaned up my code from my previous post and want to make it available for anyone to try out themselves. This code drives two 5v volt meters much like the developers have in their MkII console. Remember to set &#8220;hardware=true&#8221; in your game&#8217;s config file or else it wont work!<\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-101\" class=\"share-twitter sd-button share-icon\" href=\"http:\/\/www.wolfpack.xyz\/blog\/?p=101&amp;share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\" ><span>Twitter<\/span><\/a><\/li><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-101\" class=\"share-facebook sd-button share-icon\" href=\"http:\/\/www.wolfpack.xyz\/blog\/?p=101&amp;share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\" ><span>Facebook<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[6,7,13],"tags":[5,14],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6nSil-1D","jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/101"}],"collection":[{"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=101"}],"version-history":[{"count":4,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":113,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions\/113"}],"wp:attachment":[{"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wolfpack.xyz\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}