There are very few Tiva-C posts, and I have been unable to read a button push on the board.
- Tiva-C EK-TM4C129XL
- Blynk library V0.4.8
- Running local server (awesome idea). server-0.28.0-java8
- Energia version 1.6.10E18
- Energia is configured for “Board: “LaunchPad (Tiva-C) w/tm4c129 (120 MHz)””
- Android tablet (version 4.4.2)
- My shoe size is: 10.
I have four button widgets that control the four LEDs on the board. No problem controlling those, so I feel comfortable the tablet, server, and board are talking. I have a LED widget on V3, and have tried several of the example projects on reading a GPIO pin and pushing it via a virtual connection (including using interrupts, which interestingly caused the server to disconnect from the board - another problem for another day).
I settled on polling the button, using the example project modified for my use of a local server. Energia did not like compiling using the symbolic designation of the button (PJ0), so I used the pin number called out on the schematic (116).
My expectation is that a button push will change the state of the LED widget on the tablet. That does not happen.
My code below (I hope I am pasting it correctly, and may fail on that part of posting instructions).
Thank you for any insights.
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example shows how to use Energia with Ethernet
to connect your project to Blynk. Tested with:
TI LaunchPad (Tiva C) w/ tm4c129
Requires Energia IDE: http://energia.nu/download/
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <Ethernet.h>
#include <BlynkSimpleEnergiaEthernet.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "f89a81b91a0c4dc2958dd31d0a0361e2";
// Select your pin with physical button
const int btnPin1 = 116;
const int btnPin2 = 117;
int prevState = -1;
int currState = -1;
long lastChangeTime = 0;
void checkPin()
{
// Invert state, since button is "Active LOW"
int state = !digitalRead(btnPin1);
// Debounce mechanism
long t = millis();
if (state != prevState) {
lastChangeTime = t;
}
if (t - lastChangeTime > 50) {
if (state != currState) {
currState = state;
Blynk.virtualWrite(V3, state);
}
}
prevState = state;
}
void setup()
{
// Debug console
Serial.begin(9600);
//Running Blynke server locally on Raspberry Pi2
Blynk.begin(auth, IPAddress(192,168,1,105), 8442);
// Make push button switch pins default HIGH
pinMode(btnPin1, INPUT_PULLUP);
pinMode(btnPin2, INPUT_PULLUP);
}
void loop()
{
Blynk.run();
checkPin();
}