This file contains 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
// Variables del Sensor | |
const int pinSensor = 0; // Variable del pin de entrada del sensor (A0) | |
const int temperaturaFrio = 15; // Temperatura máxima considerada frío | |
const int temperaturaMedia = 20; // Temperatura agradable | |
const int temperaturaCalor = 26; // Temperatura mínima para ser calior | |
const int pinLedFrio = 2; | |
const int pinLedMedio = 3; | |
const int pinLedCalor = 4; |
This file contains 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
#include <Servo.h> // Incluimos la librería para poder usar el SERVO | |
Servo myservo; // Creamos nuestro objeto para controlar el servo, podemos cambiarle el nombre de "myservo" a otro si preferimos | |
// * Extra: Podríamos llegar a conectar hasta unos 12 servos en una sola placa * | |
int pos = 0; // Aquí guardaremos la posición del servo | |
void setup() { | |
// Preparación | |
myservo.attach(9); // Decimos a nuestro objeto Servo, que el micro servo real está conectado en el PIN digital 9 de la Arduino |
This file contains 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
// Incluir el código de la librería | |
#include <LiquidCrystal.h> | |
// Asociamos los PINs físicos con sus variables | |
// *EXTRA* Podemos encadenar la inicialización de variables en una sola linea cuando son todas del mismo tipo (ej: int) | |
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; | |
// Inicializar nuestra variable de LCD de tipo LiquidCrystal (incluido desde la librería) y asociando con los PINs que está conectada | |
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); | |
// Esto se ejecuta una sola vez al principio |
This file contains 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
const int LED = 13; | |
const int PIR = 5; | |
void setup() { | |
// Inicializar pin del LED como escritura | |
pinMode(LED, OUTPUT); | |
// Inicializar pin del PIR como lectura | |
pinMode(PIR, INPUT); |
This file contains 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
const int BUZZER = 9 | |
void setup(){ | |
// Marcamos el pin del buzzer en modo salida | |
pinMode(BUZZER, OUTPUT); | |
} | |
void loop(){ |
This file contains 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
fun createHttpClient(): HttpClient { | |
return HttpClient(OkHttp) { | |
// Json | |
install(JsonFeature) { | |
serializer = KotlinxSerializer(json) | |
} | |
// Logging | |
install(Logging) { | |
logger = object : Logger { | |
override fun log(message: String) { |
This file contains 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
suspend fun userLogin(emailLoginRequest: EmailLoginRequest): User? = withContext(Dispatchers.IO) { | |
try { | |
// Email Login | |
val user = httpClient.post<User>(Endpoints.Login) { | |
body = emailLoginRequest | |
header("X-Requested-With", "XMLHttpRequest") | |
} | |
user | |
} catch (t: Throwable) { | |
// Handle Error |
This file contains 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
@Serializable | |
data class Item( | |
val id: Int, | |
@SerialName(value = "title") val title: String? = null, | |
val description: String? = null, | |
@SerialName(value = "image_url") val imageUrl: String? = null, | |
@SerialName(value = "is_featured") val isFeatured: Boolean? = null, | |
@SerialName(value = "publication_date") val publicationDateString: String? = null, | |
@SerialName(value = "share_link") val shareUrl: String? = null | |
) |
This file contains 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
suspend fun uploadFile(file: ByteArray, headerValue: String) = withContext(Dispatchers.IO) { | |
try { | |
// Prepare Input Stream | |
val inputStream = file.inputStream().asInput() | |
// Create Form Data | |
val parts: List<PartData> = formData { | |
// Optional Headers | |
append("headerKey", headerValue) | |
// File Input Stream | |
appendInput("file", size = file.size.toLong()) { inputStream } |
This file contains 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
val items: List<Item> = httpClient.get<List<Item>>("https://api.example.org/items") { | |
parameter("limit", 10) | |
} |
OlderNewer