Posts

Showing posts with the label Code

Battleships in Terminal With Python

Image
BATTLESHIPS IN PYTHON This is my first project on Codecademy Computer Sciences pathway. The task was to create a terminal based game or application in python, one of the ideas provided was for battleships and it looked interesting. The game randomly places both your ships and enemy ships in the play area. Each player takes it in turn to fire at the opponents ships by entering grid details. Hits or misses are displayed on the grids. When all ship sections of a team are destroyed the game is over and a winner declared. The code can be fount at this link https://github.com/Leah9/battleships please give it a go and let me know if you found it fun or if you find an error. This project was more complex than I initially invisioned but it was satisfying to overcome some of the early issues and making a output function that was both functional and pretty. Looking forward to the next one :)

Arduino DHT22 readings over serial

Image
 Today I am going to add a DHT22 temperature humidity sensor to my existing battery voltage monitor project. Uploading and testing the code is done over USB cable, the HC-05 needs to be disconnected for this to work. The DHT22 is connected to +5v, gnd and Digital Pin 10, I only chose pin10 as it is convenient for my veroboard layout. The code for this is very simple : <code> #include "DHT.h" #define DHTPIN 2 // The pin that your DHT is connected to DHT dht(DHTPIN, DHT22); void setup() { dht.begin(); } void loop(){ float h = dht.readHumidity();     //stores humidity value in float variable h float t = dht.readTemperature();// temperature value } </code> Don't forget to import the "DHT sensor library" in library manager in the Arduino IDE.  We can then do whatever we need to with the values. I am going to send request them over serial via a HC-05 Bluetooth device from a Python script on a Raspberry Pi.  For testing  am using a laptop running ...