<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[M5stack led output not working.]]></title><description><![CDATA[<p dir="auto">Hello guys,<br />
i am trying to create a menu using Arduion and M5stack,  i wanted to test the buttons if they work, so i conected a led pin to 21 and G output, when i press start the led should go on and if i press stop the led should turn off, but it is not working how i want, the led is always on no matter what i press, but if i switch the pin output the led starts to blink when i press start or stop ,<br />
what i am trying to create is switching the led on or off when i press start or stop<br />
here is my code:</p>
<p dir="auto">bool LED_ON = false;<br />
int clockwise = 0;<br />
int counterclockwise = 0;<br />
int rest = 0;</p>
<p dir="auto">const int ledPin = 21;</p>
<p dir="auto">// Standard Arduino setup function. ez.begin() takes care of startup and initialization<br />
void setup() {<br />
#include &lt;themes/default.h&gt;                         // per <a href="https://github.com/M5ez/M5ez#themes" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/M5ez/M5ez#themes</a><br />
#include &lt;themes/dark.h&gt;                            // makes both themes available<br />
pinMode(ledPin, OUTPUT);<br />
ez.begin();                                         // initializes everything<br />
}</p>
<p dir="auto">void loop() {</p>
<p dir="auto">ez.addEvent(LEDMotor);</p>
<p dir="auto">Serial.println("entering loop()");                  // Shows what function we're in on the Serial Monitor<br />
ezMenu topmenu("Top Menu");                         // creates the menu but does nothing else<br />
topmenu.txtSmall();                                 // makes menu text smaller, neater<br />
topmenu.buttons("up # select # down");              // 'select' sets pickName and pickCaption, all set pickButton<br />
<a href="//topmenu.addItem" target="_blank" rel="noopener noreferrer nofollow ugc">//topmenu.addItem</a>("dark | Dark Theme",  dark);        // ignore in while loop, calls dark() automatically<br />
<a href="//topmenu.addItem" target="_blank" rel="noopener noreferrer nofollow ugc">//topmenu.addItem</a>("light | Light Theme", light);      // ignore in while loop, calls light() automatically<br />
topmenu.addItem("P1");                             // does nothing; handled manually in while loop<br />
topmenu.addItem("P2");                           // does nothing; handled manually in while loop<br />
topmenu.addItem("P3");                            // does nothing; handled manually in while loop<br />
<a href="//topmenu.addItem" target="_blank" rel="noopener noreferrer nofollow ugc">//topmenu.addItem</a>("Black");                            // does nothing; handled manually in while loop<br />
topmenu.addItem("Menu");                         // does nothing; handled manually in while loop<br />
while(topmenu.runOnce()) {                          // runOnce displays the menu and returns when a button is pressed<br />
// you can watch the results in the Serial Monitor<br />
Serial.printf("topmenu.pick        = %d\n",   topmenu.pick());<br />
Serial.printf("topmenu.pickButton  = %s\n",   topmenu.pickButton().c_str());<br />
Serial.printf("topmenu.pickName    = %s\n",   topmenu.pickName().c_str());<br />
Serial.printf("topmenu.pickCaption = %s\n\n", topmenu.pickCaption().c_str());</p>
<pre><code>String result  = topmenu.pickName();              // find out what menu was selected when 'select' button was pressed
if(     result == "P1")   newSubMenu(5,10,5,result);
else if(result == "P2")   newSubMenu(5,17,3,result);    
else if(result == "P3")   newSubMenu(10,10,0,result);    
</code></pre>
<p dir="auto">}<br />
}</p>
<p dir="auto">/****/<br />
void newSubMenu(int clockwise, int counterclockwise, int pause, String menuname)<br />
{<br />
Serial.println(menuname);               // Shows what function we're in on the Serial Monitor<br />
ezMenu submenu(menuname);                         // creates the menu but does nothing else<br />
submenu.txtSmall();                                 // makes menu text smaller, neater<br />
submenu.buttons("up # back # select ## down #");    // standard buttons for a submenu; long press on button A pops up one level<br />
submenu.addItem("Start");                             // not handled at all, so nothing happens when this menu is selected except a redraw<br />
submenu.addItem("Stop");                             // not handled at all, so nothing happens when this menu is selected except a redraw</p>
<p dir="auto">while(submenu.runOnce()) {                          // runOnce displays the menu and returns when a button is pressed<br />
// you can watch the results in the Serial Monitor<br />
Serial.printf("submenu.pick        = %d\n",   submenu.pick());<br />
Serial.printf("submenu.pickButton  = %s\n",   submenu.pickButton().c_str());<br />
Serial.printf("submenu.pickName    = %s\n",   submenu.pickName().c_str());<br />
Serial.printf("submenu.pickCaption = %s\n\n", submenu.pickCaption().c_str());</p>
<pre><code>if(submenu.pickName() == "Start") Motor(clockwise, counterclockwise, true); 
if(submenu.pickName() == "Stop") Motor(clockwise, counterclockwise, false); 
</code></pre>
<p dir="auto">}<br />
}</p>
<p dir="auto">/* */<br />
void Motor(int clockwise, int counterclockwise, bool spinmotor)<br />
{<br />
LED_ON = spinmotor;<br />
}</p>
<p dir="auto">uint16_t LEDMotor()<br />
{<br />
if(LED_ON){<br />
digitalWrite(ledPin, HIGH);<br />
Serial.println("LED on");<br />
}<br />
else{<br />
digitalWrite(ledPin, LOW);<br />
Serial.printlb("LED off");<br />
}</p>
<pre><code>return 1000;
</code></pre>
<p dir="auto">}</p>
<p dir="auto">/********************************************************************************************************/</p>
<p dir="auto">/****/<br />
void subMenu() {  Serial.println("Menu");               // Shows what function we're in on the Serial Monitor<br />
ezMenu submenu("Menu");                         // creates the menu but does nothing else<br />
submenu.txtSmall();                                 // makes menu text smaller, neater<br />
submenu.buttons("up # back # select ## down #");    // standard buttons for a submenu; long press on button A pops up one level<br />
submenu.addItem("foo");                             // not handled at all, so nothing happens when this menu is selected except a redraw<br />
submenu.addItem("bar");                             // not handled at all, so nothing happens when this menu is selected except a redraw<br />
submenu.addItem("baz");                             // not handled at all, so nothing happens when this menu is selected except a redraw<br />
submenu.addItem("sub | subSubMenu");                // returns the name "sub" but displays the caption "subSubMenu"<br />
while(submenu.runOnce()) {                          // runOnce displays the menu and returns when a button is pressed<br />
// you can watch the results in the Serial Monitor<br />
Serial.printf("submenu.pick        = %d\n",   submenu.pick());<br />
Serial.printf("submenu.pickButton  = %s\n",   submenu.pickButton().c_str());<br />
Serial.printf("submenu.pickName    = %s\n",   submenu.pickName().c_str());<br />
Serial.printf("submenu.pickCaption = %s\n\n", submenu.pickCaption().c_str());</p>
<pre><code>if(submenu.pickName() == "sub") subSubMenu();     // submenu.pickName() == "sub", or submenu.pickCaption() == "subSubMenu", or submenu.pick == 4
</code></pre>
<p dir="auto">}<br />
}</p>
<p dir="auto">void subSubMenu() {}</p>
]]></description><link>https://community.m5stack.com/topic/3187/m5stack-led-output-not-working</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 13:46:16 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/3187.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 12 Apr 2021 12:44:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to M5stack led output not working. on Tue, 13 Apr 2021 08:13:35 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/8630">@lasslop</a></p>
<p dir="auto">GPIO21 (pin 21) is not a lucky choice. By default GPIO21 is used as SDA (I2C). Have you tried with a different GPIO?</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/13509</link><guid isPermaLink="true">https://community.m5stack.com/post/13509</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Tue, 13 Apr 2021 08:13:35 GMT</pubDate></item></channel></rss>