Created
February 18, 2018 02:50
-
-
Save kumamotone/8c6caf69c9ee0213a45a4a7292864c17 to your computer and use it in GitHub Desktop.
WeatherStationActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Log.d(TAG, "Weather Station Started"); | |
try { | |
mDisplay = RainbowHat.openDisplay(); | |
mDisplay.setEnabled(true); | |
mDisplay.display("OK "); | |
Log.d(TAG, "Initialized I2C Display"); | |
} catch (IOException e) { | |
throw new RuntimeException("Error initializing display", e); | |
} | |
try { | |
if(ledstrip != null) | |
{ | |
ledstrip.close(); | |
} | |
} catch (IOException e) { | |
Log.d(TAG,e.toString()); | |
} | |
final FirebaseDatabase database = FirebaseDatabase.getInstance(); | |
final DatabaseReference reference = database.getReference("googlehome").child("word"); | |
reference.addValueEventListener(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
String str = dataSnapshot.getValue(String.class); | |
if (TextUtils.equals(str, "party")) { | |
try { | |
int[] rainbow = new int[7]; | |
ledstrip = RainbowHat.openLedStrip(); | |
ledstrip.setBrightness(1); | |
for (int i = 0; i < rainbow.length; i++) { | |
rainbow[i] = Color.HSVToColor(255, new float[]{i * 360.f / rainbow.length, 1.0f, 1.0f}); | |
} | |
ledstrip.write(rainbow); | |
} catch (IOException e) { | |
Log.d(TAG,e.toString()); | |
} | |
Log.d("party!", str); | |
} | |
} | |
@Override | |
public void onCancelled(DatabaseError databaseError) {} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment