Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IKS01A1
Diff: main.cpp
- Revision:
- 5:dd52b4b8a40b
- Parent:
- 4:9b7d5033d0ef
- Child:
- 6:c4c88077923c
--- a/main.cpp Thu Jan 16 17:14:12 2020 +0000 +++ b/main.cpp Tue Jan 21 10:37:49 2020 +0000 @@ -212,7 +212,48 @@ led1 = false; } else if (idx == 3) { - printf("3 \n"); + printf("Þrýst á takkann %7ld sinnum \r\n", idx); + while(1){ + char buffer1[32], buffer2[32]; + int32_t axes[3]; + accelerometer->get_x_axes(axes); + int max_1 = max(abs(axes[0]), abs(axes[1])); + max_1 = max(max_1, abs(axes[2])); + + if (max_1 == abs(axes[0])) { + if (max_1 == axes[0]) { + printf("RIGHT \n"); + led1 = !led1; + wait(0.2); + } else { + printf("LEFT \n"); + led1 = !led1; + wait(0.2); + } + } + else if (max_1 == abs(axes[1])) { + if (max_1 == axes[1]) { + printf("TOP \n"); + led1 = !led1; + wait(0.2); + } else { + printf("BOTTOM \n"); + led1 = !led1; + wait(0.2); + } + } + else if (max_1 == abs(axes[2])) { + if (max_1 == axes[2]) { + printf("UP \n"); + led1 = 1; + wait(0.2); + } else { + printf("DOWN \n"); + led1 = !led1; + wait(0.2); + } + } + } } else if (idx > 3) { break; @@ -240,11 +281,11 @@ gyroscope->read_id(&id); printf("LSM6DS0 accelerometer & gyroscope = 0x%X\r\n", id); - wait(3); + wait(1); while(1) { int userInput; - cout << "Veldu tilfelli 1-7: " << endl; + cout << "Veldu tilfelli 1-3: " << endl; cin >> userInput; switch(userInput) { case 1: tilfelli1();